Geertjan's Blog

  • May 30, 2007

Managing NetBeans Project Templates

Geertjan Wielenga
Product Manager
Although it's not hard to create NetBeans project templates, it's quite painful to have to update them, unless you know about what I'm going to tell you about in this blog entry. A project template is created by a wizard and each consists of a number of things. Firstly, most importantly, the template itself, in the form of a ZIP file. The template is normally an entire application, with its own sources and build files, and so on. But, in addition, a project template includes an HTML file with a description that will be shown in the New Project wizard. It also contains an icon. It also contains an XML layer file that registers the project template. It also contains a Bundle file. Hence, what happens when you update the application that you're distributing as a template? Do you need to work through the Project Template wizard again and provide all those various items all over again?

And the answer is "no". There's no need to go through the Project Template wizard again, each time you update the application. Why? Because of Ant. You can provide an Ant target, in the application that you want to distribute as a template, to create a new ZIP file whenever you change it. And you can use the Ant target to specify where the ZIP file should be created. Thus, you can pop that ZIP file automatically into the project template's source structure, overwriting the existing ZIP file. As a result, updating your project template is very easy. I learned this from Jesse, who provides this very useful Ant script as an illustration.

The nicest thing would be, in my opinion, if the application was rezipped whenever I build it. There don't seem to be handy hooks like -post-jar in the module development world, so I simply copied the build target from build-impl.xml, into build.xml. And then I added my own few lines after that, so that I had an overridden build target, extended with my ZIP functionality. Below, only the highlighted lines are my own, the rest is the standard build target in module projects:

<target name="build" depends="-init,branding" description="Build all modules in the suite.">
<subant target="netbeans" buildpath="${modules.sorted}" inheritrefs="false" inheritall="false"/>
<mkdir dir="${cluster}/config/Modules"/>
<createmodulexml xmldir="${cluster}/config/Modules">
<hidden dir="${netbeans.dest.dir}">
<custom classpath="${harness.dir}/tasks.jar" classname="org.netbeans.nbbuild.ModuleSelector">
<param name="excludeModules" value="${disabled.modules}"/>
<param name="excluded" value="true"/>
</createmodulexml><property name="build.classes.dir" location="/home/geertjan/Desktop/TextFileDictionaryProjectTemplate"/>
<property name="examples" location="${build.classes.dir}/src/org/netbeans/modules/textfiledictionaryprojecttemplate/"/>
<zip basedir="../TextFileDictionaryProjectTemplate" destfile="${examples}/TextFileDictionaryProjectTemplateProject.zip">
<exclude name="\*\*/build/"/>
<exclude name="\*\*/dist/"/>
<exclude name="\*\*/nbproject/private/"/>


As a result of the above, my project template's ZIP file, which contains the application that I want to distribute as a template (or as a sample, which comes down to the same thing) is updated whenever I build my application. Hurray.

Join the discussion

Comments ( 7 )
  • Thomas Zillinger Wednesday, May 30, 2007
    How about if you'd put your very helpful(!) tips also on http://wiki.netbeans.org/wiki/view/CommunityDocs since not everyone knows your blog :) (although they should \*ggg\*)
  • Javier Molina Thursday, May 31, 2007
    There's a better way to customize the build file; instead of copying the whole target, do this:

    <target name="build" depends="suite.build">
    <your custom tasks/>

  • leonardoavs Wednesday, February 15, 2012

    Hi do you have more information about this topic I am very interested in know how to develop a Netbeans project template.

  • Geertjan Wednesday, February 15, 2012
  • leonardoavs Thursday, February 16, 2012

    Thanks for the information.

  • leonardoavs Thursday, February 16, 2012

    Do you know if I can use the java auto completion in a JTextfield swing component, Example: the auto completion that the Watches windows has.

  • Geertjan Thursday, February 16, 2012

    Here's the place to ask general NetBeans API questions: dev@platform.netbeans.org

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.