Share

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 pom.properties in the war's META-INF/ directory in the following format "META-INF/maven///pom.properties"

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


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

App Version: <%= mainVer %>