October 2, 2008

Displaying Maven POM Version in a JSP

So in most web apps you want to know what version is deployed to the server and with maven that is easy. When maven builds a war file it creates a in the war's META-INF/ directory in the following format "META-INF/maven///"

Here is how to read that file and display the version of the pom on a jsp page...

<%@ page import="java.util.*"%>
<% in = getServletContext().getResourceAsStream("META-INF/maven/groupid/artifactid/");
    Properties mProps = new Properties();
    String mainVer = (String) mProps.get("version");

App Version: <%= mainVer %>