Get the application version information from the META-INF/MANIFEST.MF file inside the jar file

A need that we often meet is how to know what version of the application we are running, so we can know what features the application is supporting up to this version. In Java, depending on what application you are using, Web application or Desktop application, the way to get version information of the application will be different. For Java Desktop or Java Console applications, you can store and get the application’s version information from the META-INF/MANIFEST.MF file inside the application’s jar file.

For example, I have a Java Console application that when run will print the words “Hello from Huong Dan Java”:

I used Maven Shade Plugin to build this application, and when building the application, I added some information related to the application in the META-INF/MANIFEST.MF file inside the jar file as follows:

Among these, the “Implementation-Version” header information contains information about the version of the application.

To get this information and display it to the application, you can use the following code:

with class Application being any class of the application.

My example is as follows:

then when you rebuild the application and run it, you will see the following results:

Add Comment