When I was working with XCode and iOS, there was a simple way to check the application’s current version by reading the plist.
Is there a similar way to do this in Java?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
XCode stores that version value in a resource file that is distributed with your application. In Java the equivalent would be your Manifest file, which is packed inside your JAR/WAR/EAR archive.
A Manifest file is just a metadata text file named
MANIFEST.MFthat stores some standard key/value pairs which are recognized by many tools and that is packaged inside a special folder namedMETA-INFinside your java archive.To get the Manifest file for your own JAR this question would give you some clues. Once you have your own
Manifestinstance then use either one of the next options to get that version value.This way to get the Specification Version:
This way to get the Implementation Version:
More info regarding the JAR manifests can be found here.
EDIT:
If you are getting
nullvalues for any of those properties that means that they haven’t been configured in yourMANIGEST.MFfile. That’s easy to check: unzip your JAR file (JAR files are just ZIP files with a different extension name) and go theMETA-INFfolder to find theMANIFEST.MFfile, since it’s a text file you can print its contents to the console, if there is aSpecification-VersionorImplementation-Versionattribute defined there and you are still gettingnullvalues then you might be loading a manifest file from a different JAR.FOR THE RECORD:
To get that attributes in your Manifest file you would need to configure your build tool to do so. Maven would do it automatically (you can customize it though), with Ant you will need to use a specific Ant Task, with Eclipse you will need go through its docs (same with any other IDE).