How to get Web Package Version using maven

Objective:

To demonstrate a way to retrieve java package version by programatically.

Demonstration Steps:

Step-1: Generate Version Info using Maven

Click to visit maven pom changes here 

To add package version info into the bundle as war. To achieve this, need to add some additional setting parameter in pom.xml of web project like below.

Above parameter will add a META-INF/MENIFEST.MF file which holds package information in below format.

Implementation-Version holds the current package version which is 0.0.1.SNAPSHOT

Step-2 Read MENIFEST.MF using Java

Click to visit Java Implementation to read the version from file

Conclusion:

Finally, the output of application version in browser will be

Alert!

Same thing you can be implemented by rest services as well but the core logic will be remain as it is.

Note: Eclipse does not create MENIFEST.MF file in war exploded version in target folder but add this file to the WAR. IntelliJ and other maven based IDE used WAR exploded version therefore there won’t be any issue with in IDE except eclipse.

 

share or like this post
Share

Leave a Reply

Your email address will not be published. Required fields are marked *

Share