Search code examples
javasvnweb-applicationsrevision

obtain current svn revision in webapp


what is the best way of displaying/using the revision number in a java webapp?

we just use ant to build our .war archive, no buildserver or such. i'd hope there was some kind if $ref that i could write in a resource file, but this is only updated when the file in question is committed. i need it globally.

what would you recommend? post-commit triggers that update certain files? custom ant scripts? is there a more non-hacky way of doing this? or it it better to have my own version number independent of svn.

edit: great suggestions! thanks a lot for the answers!


Solution

  • There are a couple of Ant tasks that can do this for you.

    SvnAnt task from tigris is the oldest.

    Documentation is here - in particular take a look at the info element which exposes the Subversion repository's revision number as an Ant property which it calls rev. You can write this value to your resouces file using the normal Ant substituion mechanisms.

    Someone has also put up a simillar (simpler) task on google code hosting - never used it though so can't comment.

    Either of these seem like the neatest way to me if you already have Ant in your build.