Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load Maven POM version number into Java Project

I want to add a version numbering to my Java application (in this case a Vaadin Portlet) which features the Version number in the help view.

The thing is that that version number is the one defined in the my Maven's POM file (for example 1.1.5-SNAPSHOT) and that is the one we are going to change (at release for example).

Any idea on how to get it out of the POM and into (for example, a String) in Java? (If this is at all possible)

Thanks

like image 730
Fverswijver Avatar asked Mar 10 '11 13:03

Fverswijver


2 Answers

Use a filtered properties file containing the line

version=${project.version}

and load this properties file from the classpath in your Java program.

like image 171
JB Nizet Avatar answered Oct 03 '22 02:10

JB Nizet


There are many solutions to this problem

  • Have maven write the version number in MANIFEST.MF during packaging phase
  • Create a filtered properties file, like JB mentionned
  • Have one Java class rewritten with that property

But I would defintely prefer the first, as accessing MANIFEST.MF is quite easy in Java

like image 23
Riduidel Avatar answered Oct 03 '22 02:10

Riduidel