I am using Maven 2 to build my Java project and I am looking for a way to present the current version number of the pom.xml to the user (using a Servlet or JSP for example).
I solved this problem a little differently, as I had a desire to display version, svn revision, etc. on the index page of a service. I used the buildnumber-maven-plugin and the war-plugin to store the values in the manifest.
pom.xml snippet:
org.codehaus.mojo
buildnumber-maven-plugin
validate
create
maven-war-plugin
true
${env}
${buildNumber}
package
war
${env}
The JSP to pull them out was fairly trivial:
<%@ page language="java" pageEncoding="UTF-8"%>
<%
java.util.jar.Manifest manifest = new java.util.jar.Manifest();
manifest.read(pageContext.getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF"));
java.util.jar.Attributes attributes = manifest.getMainAttributes();
%>
Health Check
Health Check
Version: <%=attributes.getValue("Implementation-Version")%>-<%=attributes.getValue("Implementation-Environment")%>
SVN Revision: <%=attributes.getValue("Implementation-Build")%>
This displayed something like:
Version: 2.0.1-SNAPSHOT-QA
SVN Revision: 932