Search code examples
javapropertiesjboss

Get build timestamp on JBoss application


We have a web application on JBoss 7.2. Now I want to display the build timestamp in my UI for debugging purposes, so I added

  • a properties file looking like that:
version=${pom.version} 
build.date=${timestamp} 
  • in the POM properties:
<properties>
    <timestamp>${maven.build.timestamp}</timestamp>
    <maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>
</properties>

On build, this successfully generates a .properties file with the correct values, e.g.

version=0.1-SNAPSHOT
build.date=2021-08-25 12:00

However, when deployed, that properties file isn't available anymore. I get a FileNotFoundException when my frontend bean tries to access the file via

String propertyPath = "src/main/resources/version.properties";
try (InputStream properties = new FileInputStream(propertyPath)) {

    Properties prop = new Properties();
    prop.load(properties);
}
...

Now of course I can add the properties to my standalone.xml, but I wasn't able to replace the values during build time. Any tips on how to make it work?


Solution

  • The problem you are experiencing makes total sense. You are attempting to read the file using the source code path src/main/resources/version.properties. Since you have built your app and created a jar out of it, the file in question no longer resides under this path.

    You should therefore attempt to load the file using the classloader. Check more on that here.