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 %>

5 comments:

  1. Exactly what I was after. Thanks

    ReplyDelete
  2. I've managed to read pom.properties from inside the war-file containing the jsp. But I want to read pom.properties from ALL wars deployed in the same container.

    ReplyDelete
  3. Hello,
    Thanks for this usefull post.

    I would just point out that, if you JSP is not directly under root context, you should prefix it by / your ressource URI :

    java.io.InputStream in = getServletContext().getResourceAsStream("/META-INF/maven/groupid/artifactid/pom.properties");


    :)

    ReplyDelete