Category Archives: SVN

How to show current version in an JBoss application

The problem

I want the current release version in my page footer on my JBoss/JSF application. After searching for a simple solution for a while I came up with something. I’m using maven to build the release version and Subversion are used as version control system. Maven have plugins for writing the pom version and svn revision number into the manifest file that end up in the war archive. The problem was to read that manifest file. The manifest file can be loaded by the ServletContext, but I did’n find a way to get hold of the context. I’m still convinced that there are a simpler solution, but as this is (another) hobby project it’s good enough.

I found a much simpler solution to the problem of getting hold of the servlet context (link) thanx to this blog:

It’s not that obvius and a lot of ’dot train’, but I can get rid of the listner code:

ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();

The solution

First the following plugins have to be added or updated in the pom file, in the build section, to generate the revision:

		<!-- Java EE 6 doesn't require web.xml, Maven needs to catch up! -->

Be sure to set the useLastCommittedRevision to true.

Running mvn package will genrate a war file containing a MANIFEST.MF file in the META-INF folder. The meta-inf file will contain the following version information:

revision: 12
Implementation-Version: 0.0.1-SNAPSHOT (if addDefaultImplementationEntries = true)
Specification-Version: 0.0.1-SNAPSHOT (if addDefaultSpecificationEntries=true)

Get hold of the ServletContext

With the information in the manifest file we just have to read it and show it on the page, and here it becomes a bit tricky. When running Spring on a Tomcat server I can get the ServletContext injected into my bean, but I didn’t found out how to do it on Jboss with CDI. The only way to get hold of the ServletContext was to set up an ServletContextListener and read the manifest file at application startup.

public class ServletContextProvider implements ServletContextListener {
	private Logger log;
	private static String version = "Unknown";
	public String revision() {
		return version;
	public void contextInitialized(ServletContextEvent contextEvent) {
		ServletContext context = contextEvent.getServletContext();
		Properties prop = new Properties();
		try {
			version = prop.getProperty("Implementation-Version");
			String revision = prop.getProperty("revision");
			if (revision.length() &gt; 1)
				version += " Revision:" + revision;
		} catch (IOException e) {
			log.warning("Fail to read manifest file on ServletContext:"
					+ e.getMessage());
	public void contextDestroyed(ServletContextEvent contextEvent) {"Context Destroyed");
		version = "Unknown";

This listener have to be configured in the web.xml file (not needed with the new solution):


And at last, show it in the page! I put it into the footer in the page template: