In the footer of a webpage application we want to have its version and its SVN revision number. We also want this to be done without hardcoding the number, but to update automatically with every new deployment. When the SVN Revision Number of the project changes, then it should automatically be updated on the web page too.
First of all we need a simple properties file:
repository = ${prefix.repository}
path = ${prefix.path}
revision = ${prefix.revision}
mixedRevisions = ${prefix.mixedRevisions}
committedRevision = ${prefix.committedRevision}
committedDate = ${prefix.committedDate}
status = ${prefix.status}
specialStatus = ${prefix.specialStatus}
project_version = ${project.version}
This file is filled by the Maven SVN Revision Number plugin which we define in our pom.xml:
Since we do continuous integration, we also need to make sure that Hudson uses the plugin correctly, when deploying the project onto Wildfly. This is where the Wildfly Maven Plugin comes into play:
When Hudson is now running the job, the azn.properties file is filled by Maven and put into the WAR “at the right time”. For example if in the above code we change <phase>deploy</phase> to <phase>compile</phase>, the plugin will run and everything will look fine, but the properties file that is actually put in the WAR won’t be the one that Maven has updated.
After all this is done correctly, one can simply read the properties file in JAVA from a backin bean and in our case display it on a JSF page as seen above.
A lot of time went into finding out, why the azn.properties file in the WAR is not having any revision numbers in it even though the plugin is running correctly.In conclusion we discovered, that defining the SVN Revision Number Plugin in the pom.xml is not enough. We also need to configure the wildfly maven plugin correctly, so that the azn.properties file gets filled AND packaged into the WAR.
Many Thanks to Daniel Holderbaum for helping with the configuration in the poms and finding the necessary plugins.