This is post is NOT about version control in the sense of source code control. It addresses the issue how to easily tell which version of the Web application is running as well make sure that the same version is reflected in the snapshots performed by Ant. We have used this approach on several applications and found it quite useful.

The version I talk about is not the automatically generated version from VCS system (such as SVN revision). The version number is set manually.

In every project, we include property file named, placed at the root of the classpath (next to 'com' directory in the source tree). The content can look like this

[sourcecode language='java'] = MyApp
app.version = 0.5.4 = User authentication implemented

[/sourcecode]This property file will be available to Java code because of its location in classpath. Our build.xml file ususally starts with few includes like this

[sourcecode language='xml']

[/sourcecode]We try to load first the property files named after the computer. This way we can easily address differences in e.g. Tomcat locations, pathnames to libraries etc. This is very useful if not all team members have identical development environment - which is almost always the case, as I am on Mac and the others mostly on Windows :-). The environment variable COMPUTERNAME is automatically set for you if you are on Windows, for Mac/Linux users all you need is an export in your .bashrc file.

The second include loads the application properties and makes the 'app.version', '' available for Ant tasks. Externalizing the allows reusing same Ant script for multiple project. Here is an example of the task that creates and archive of current source code snapshot using this information:

[sourcecode language='xml']

[/sourcecode]The DSTAMP and TSTAMP are set in prepare task:

[sourcecode language='xml']

[/sourcecode]To access the information from, we simply add it to the list of message sources:

[sourcecode language='xml']


[/sourcecode]This allows to easily display the version number and information as part of e.g. JSP page:

[sourcecode language='xml']


[/sourcecode]For production, I usually still leave the version in the JSP, only include it in HTML comments, so that it does not interfere with the UI but is still accessible by viewing page source.

I usually set version number and info string manually, but it possible to automatically write information about e.g. build date and time of the application and make it a part of the version info. To do that, use the Ant task:

[sourcecode language='xml']

File updated at ${DSTAMP} ${TSTAMP}
[/sourcecode]In this case, the value of property app.stamp will be overwritten every time the 'set_version' task executes.