How to get the pom properties at runtime?

Maven Properties Jam
I recently needed to access some of the pom properties at runtime. To be more specific, I needed the version related properties: artifact id, group id, and version. It turned out that there are at least three ways do that.

Each of the three approaches has its upsides and downsides. You feel free to pick the one that suits you the best.

Get the version info from the manifest

The correct place to find the version info is the manifest of the jar file. Maven unfortunately does not add it there by default. You can instruct maven to do that for you by properly configuring the maven-jar-plugin.


The important moment here is to set the <strong>addDefaultImplementationEntries</strong> value to true. This tells maven to add the following values to the manifest file:

  • Implementation-Title: ${}
  • Implementation-Version: ${project.version}
  • Implementation-Vendor-Id: ${project.groupId}
  • Implementation-Vendor: ${}
  • Implementation-URL: ${project.url}

After the jar artifact is built in this way, getting the info in the code is easy:

Package mainPackage = Main.class.getPackage();
String version = mainPackage.getImplementationVersion();
String groupId = mainPackage.getName();
String artifactId = mainPackage.getImplementationTitle();

This maybe is a bit more difficult to test but it is a very easy and straightforward. However, if you need to access any other pom properties, this won’t work.

Get the pom properties using filtering

Maven has the option of filtering. It allows you to replace variables in your resource files with actual values of pom properties. First, create a file in your resource folder. The name of the file is arbitrary. Add the variables you need to the file:


Next, configure the resource section of the build stage:


This instructs maven to go over the files and change all the variables with actual values. After you build the project the file can be found in the resulting jar, containing all the real values. All you need to do then is read the property file as you would read any other property file in java:

Properties properties = new Properties();

String version = properties.getProperty("version");
String artifactId = properties.getProperty("artifactId");
String groupId = properties.getProperty("groupId");


Get the pom properties using the properties plugin

Maven has a <a href=””>dedicated plugin</a> for getting pom properties in and out of files. This is how you configure writing the properties to a file names


This will write all properties defined in the properties section of the pom into the file. But this has its downside. If you want a property to appear in the file, you will have to define it in the properties section. The version info does not appear there by default.

Sharing is caring