1. Pom.xml
<maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<version>2.1.1</version>
<configuration>
<archive>
<manifestEntries>
<SCM-Revision>${maven.build.timestamp}</SCM-Revision>
</manifestEntries>
</archive>
</configuration>
</plugin>
2. Java code.
public static String getProjectVersion() {
ServletContext application = Sessions.getCurrent().getWebApp().getServletContext();
InputStream inputStream = application.getResourceAsStream("/META-INF/MANIFEST.MF");
Manifest manifest;
try {
manifest = new Manifest(inputStream);
Attributes attr = manifest.getMainAttributes();
return attr.getValue("SCM-Revision");
} catch (IOException e) {
e.printStackTrace();
}
return "";
}
No comments:
Post a Comment