After going through a couple of guides on the net, I figured out how to add build numbers and revision numbers to my NetBeans projects. The build number will be incremented for each build, and the revision number is gathered from your subversion repository. If you don’t use Subversion just skip that part and add the revision number manually.
In this tutorial I assume you are creating an application based on the NetBeans Desktop Application wizard. Otherwise, you may just follow along and use whatever fits into your project. All you need is a java project being built by Ant (as all NetBeans projects are).
Adding a build number
First of all, figure out where the properties file for your application is located. This should be in [package name].resources (or if you are browsing the files, you will find it under /src/[package name]/resources) and is named the same as your application with the suffix “.properties“.
This could for instance be myapp.resources/myapp.properties or /src/myapp/resources/myapp.properties.
Open it up and find the version property. It should look something like this:
Application.version = 1.0
Change this to the following
Application.version = 1.0.0.${Application.buildnumber}
Now, we are ready to add a build number to your build.xml file. This is found in the nbproject folder if you browse for files (not in the Projects browser).
Add the following lines below the
<import file="nbproject/build-impl.xml"/>
by replacing [Package Name] and [App Name] with your own values.
<target name="-post-jar" description="Sets the buildversion for the current build">
<propertyfile file="${src.dir}/[Package Name]/[App Name].properties">
<entry key="Application.buildnumber" value="1" type="int" operation="+"/>
</propertyfile>
</target>
This should now add your build number to your version number. If you want to have the version in the main title bar of your application just go back into the properties file and change the Application.title property to something like this:
Application.title = My Application Name ${Application.version}
Adding the Subversion revision number
Go back to your build.xml file and add the following below everything else:
<target name="-post-init" description="Sets the buildversion for the current build">
<exec outputproperty="svna.version" executable="svnversion">
<arg value="-c" />
<redirector>
<outputfilterchain>
<tokenfilter>
<replaceregex pattern="^[0-9]*:?" replace="" flags="g"/>
<replaceregex pattern="M" replace="" flags="g"/>
</tokenfilter>
</outputfilterchain>
</redirector>
</exec>
<propertyfile file="${src.dir}/[Package Name]/[App Name].properties">
<entry key="Application.revision" value="${svna.version}" type="int" operation="="/>
</propertyfile>
<echo>Revision found from SVN: ${svna.version}</echo>
</target>
Then, add the revision number to your version number by editing changing the Application.version property to something like this:
Application.version = 1.0.${Application.revision}.${Application.buildnumber}
This should be all it takes. Just leave a comment if it does not work out as expected.


Hi,
there seems to be something missing after
Add the following lines below the by replacing [Package Name] and [App Name] with your own values.
and
Go back to your build.xml file and add the following below everything else:
Doesn’t seems to be working anymore, bellow everything else? Below ?
I’m using netbeans 6.9
Do you have a solution? Would be much appreciated
Hi Sebastian!
Thanks for pointing this out. It seems like the syntax highlighter WP-Syntax didn’t handle the WordPress editor too well and ended up escaping all relevant code. I’ve replaced the highlighter with a new one, so the code should be up and running again. Seems like it has been missing for quite some time, so again, thanks for finding this error.
If the method described in this post still works for Netbeans 6.9, please give me a note. I haven’t tested it since 6.7.
Hi..
nice.. do you have for NetBeans 6.9 version?
thanks a lot in advance
Regards
Pingback: getImplementationVersion() returns null - Page 2 - Java Forums
I haven’t tested the code with NetBeans 6.9, but according to the above pingback it appears to still be working. Just post back if you encounter any errors.
Really helpful post. Thanks a lot.
Glad to hear it helped you out!
Thanks for this useful post. Works for me in NB7. I made a few changes to output the version to a HTML template so it could be included in the footer.
${Application.version}