use maven to update the version number in your application

Sometimes you want to reference the build version in your java code and so inyor application. Maybe you also may want the timestamp (when your program has been build) or any other info that maven would provide during build and test.

Here a simple way to manage this with maven:

Just share the variables between maven and java with a simple property-file situated in the resources folder.

  • Step one in the pom.xml

Reference the property-file within your pom. This is done with the resources element and if needed add some additonal variables that you want to have shared (here the maven buildtime).

        <!-- use this to update the build time in your java code -->
  • Step two add a property-file e.g. in your resources folder:


All the variables that are defined in maven can be referenced form the property-file:

  • Last step small java-class

A small java bean in ApplicationScoped could read out your property file:

package ch.energie_pool.influxdb.helper;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Properties;

import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;

public class ApplicationBuildInfo {
    private String version;
    private LocalDateTime buildtime;

    public void init() {
        try {
            InputStream in = getClass().getClassLoader().getResourceAsStream("");
            if (in == null)
            Properties props = new Properties();
            version = props.getProperty("build.version");
            DateTimeFormatter isoFormatter = DateTimeFormatter.ISO_INSTANT;
            Instant dateInstant = Instant.from(isoFormatter.parse(props.getProperty("build.timestamp")));
            buildtime = LocalDateTime.ofInstant(dateInstant, ZoneId.of(ZoneOffset.UTC.getId()));
        } catch (IOException e) {
            // TODO Auto-generated catch block
    public String getVersion() {
        return version;
    public void setVersion(String version) {
        this.version = version;
    public LocalDateTime getBuildtime() {
        return buildtime;
    public void setBuildtime(LocalDateTime buildtime) {
        this.buildtime = buildtime;

With annotation @Named it is now possible to directly access the info out the JSF.

What a nice thing!

🙂 ciao marco