7Feb/100
Product Versioning With Maven
Each mavenized project has its own version. Sometimes it is useful to have access to the project version from the code. For instance, display project version in the about box or on the info page.
Here is the way to do that.
Under src/main/resources create project.properties file:
version=${project.version}
In the pom.xml enable filtering:
<build>
...
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
...
</build>
And all you have to do is access project.properties file from your code.
Moreover, you can add other properties such as project name and build time.
To add name of the project add following to project.properties:
name=${project.name}
To add build time in the pom.xml add:
<project>
...
<properties>
<maven.build.timestamp.format>yyyy MMM dd HH:mm</maven.build.timestamp.format>
<buildTimestamp>${maven.build.timestamp}</buildTimestamp>
</properties>
...
</project>
And in the project.properties add:
buildTimestamp=${buildTimestamp}