Can values defined in MANIFEST.MF be accessed programmatically?
Solution 1:
Many of the values in the MANIFEST.MF can be accessed programmatically without having to find and/or open the jar file itself.
The class java.lang.Package
provides access to the ImplementationTitle
, ImplementationVendor
, ImplementationVersion
, SpecificationTitle
, SpecificationVendor
and the SpecificationVersion
.
Information about signed classes can be found using the CodeSource
class, which can be retrieved via Class
.getProtectionDomain()
.getCodeSource()
Solution 2:
Open the file with JarFile
and then call getManifest()
to get the Manifest
. After that you can access the attributes appropriately.
Solution 3:
Here's a simple example of reading the main attributes from a JAR's manifest in situ. It's handy for checking up on what's actually there.
Solution 4:
Use following way to detect External Jar/SDK MANIFEST.MF Info. We could use this info for detecting Jar version etc. Use http://docs.oracle.com/javase/6/docs/api/java/util/jar/Manifest.html
public void getSDKInfo() {
Package pkg = Manifest.class.getPackage();
String specTitle = pkg.getSpecificationTitle();
String vendor = pkg.getSpecificationVendor();
String version = pkg.getSpecificationVersion();
}