Can I access the values defined in a java manifest from code?
5 Answers
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()
- 302,674
- 57
- 556
- 614
-
Thanks! Do you happen to know if thats also available to android? – er4z0r Feb 04 '10 at 11:20
-
Personally I don't know, but it seems like it: http://developer.android.com/reference/java/lang/package-summary.html – Joachim Sauer Feb 04 '10 at 11:24
-
Thanks. I checked it again and found that Jon's solution provides more flexiblity and is available on android as well. – er4z0r Feb 09 '10 at 09:38
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();
}
- 830
- 9
- 29
- 5,418
- 6
- 48
- 92
Try com.jcabi.manifests.Manifests utility class from jcabi-manifests. Using this class you can read all available MANIFEST.MF files with one liner:
String name = Manifests.read("Foo-Name");
Also, see this article: http://www.yegor256.com/2014/07/03/how-to-read-manifest-mf.html
- 102,010
- 123
- 446
- 597