• 2.1.0

Versioning of JAR/WAR Application

Oracle recommends to use MANIFEST.MF for versioning of a Java application. We also recommend to use Manifests utility class for reading version data in runtime. For example, you're developing a web application and want to show its currently deployed version number somewhere in the HTML page. You can see how it works, for example, in www.s3auth.com. Pay attention to the small gray rectangle at the right bottom corner of the HTML page. It contains the version of the application and its Git revision hash. Every time a new version is deployed to the production server we see a new hash there. It is very convenient for developers and end-users.

You can see how it is done in www.s3auth.com by reading their pom.xml at Github. Let's reproduce it here step by step.

First, you should retrieve the revision number from your SCM (either it is Git, SVN, Mercurial, or something similar). We're using buildnumber-maven-plugin:


With a default configuration this plugin will retrieve revision number and save it into buildNumber Maven property.

The next step is to set your custom META-INF/MANIFEST.MF attribute to this generated value. maven-war-plugin has a special configuration property exactly for this purpose:


After packaging of your WAR artifact take a look at META-INF/MANIFEST.MF file. You will see something like this (if you're using Git):

My-Version: 1.0-SNAPSHOT
My-Hash: d1cd2d628c3b56ab2766a0a658c040724e13d3ba

The last and final step is to read these values in the application and show them to the end-user inside HTML. If you're using JSP:

    <div id="version">
      <%= com.jcabi.manifests.Manifests.read("My-Version") %>
      <%= com.jcabi.manifests.Manifests.read("My-Hash") %>

That's it.