Reputation: 1505
How or generally is it possible to reference to the tags from the pom.xml in java? You can make a reference in the pom with e.g.: <outputDirectory>${project.build.directory}
.
But i want to do something like that:
...
System.out.println(${project.version});
...
Is this possible?
Upvotes: 2
Views: 1356
Reputation: 4039
At build time you can filter some resource files so that at runtime you read the file and get the values you are looking for:
http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
Or if it is more complexe you can use the assembly plugin:
For example: src/main/resources/info.properties
VERSION=${project.version}
And at runtime:
Properties props = new Properties();
props.load(this.getClass().getResourceAsStream("info.properties"));
System.out.println(props.get("VERSION"));
Upvotes: 3