Friday, August 16, 2013

JSP in a WAR showing maven version

I have googled the planet for a simple solution to displaying the build version of the war project in a JSP.



If you use a war plugin, then you might try filtering.



Personally I HATE maven so, after a few failed attempts, I have simply done this and it works magically:




in my jsp I simply read a file in META_INF folder:


Properties mavenproperties = new Properties();
mavenproperties.load(getServletConfig().getServletContext().getResourceAsStream("META-INF/maven/com.acme.tools/wlobelix/pom.properties"));
out.write("
obelixversion=" + mavenproperties.getProperty("version") + "
");




being wlobelix my artifactIdand and com.acme.common my groupId




pom.properties contains:



 


#Generated by Maven
#Fri Aug 16 15:38:28 CEST 2013
version=1.8-SNAPSHOT
groupId=com.acme.common
artifactId=wlobelix






No comments: