One approach that will work: use Maven filtering to put a file in your WAR or JAR containing the required information. Then in your Java webapp, load that file's contents as a ClassPath resource InputStream
.
Create a file (let's say "buildInfo.properties") under src/main/resources
containing something like:
build.version=${project.version}
build.timestamp=${timestamp}
Note that due to an open defect, you need to define the timestamp
property as follows in the <properties>
block of your pom:
`<timestamp>${maven.build.timestamp}</timestamp>`
During your build, this file will be filtered with the value of project.version (which you define with <version>
in your pom.xml, when you specify
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
In your Java code (JSF bean, whatever), have code like the following:
InputStream in = getClass().getClassLoader().getResourceAsStream("buildInfo.properties");
if (in == null)
return;
Properties props = new Properties();
props.load(in);
String version = props.getProperty("build.version");
// etc.
If your framework supports loading properties as "Resource Bundles" from the classpath (i.e. like in Spring), no need for the preceding Java code that loads the properties file.