I'm trying to extract information from my manifest file to display in one of the methods in my jar
file, but seem to be having some issues. Any help is appreciated.
Manifest file:
Manifest-Version: 1.0
Created-By: 1.8.0_60 (Oracle Corporation)
Main-Class: com.example.package1.myClass
Name: com/example/package1
Specification-Title: MyPackage
Specification-Version: v1.1
Specification-Vendor: MyCompanyName
Implementation-Title: MP
Implementation-Version: 2015-11-05-C
Implementation-Vendor: MyName
Name: com/example/package2
Specification-Title: MySecondaryPackage
Specification-Version: v2.0
Specification-Vendor: MyCompanyName
Implementation-Title: M2ndP
Implementation-Version: 2015-11-05-C
Implementation-Vendor: MyName
myClass.java:
package com.example.package1;
import com.example.package2;
class myClass {
public static void main(String[] args) {
try {
myClass clz = new myClass();
Thread.sleep(10000); //pause 10 seconnds so we can see what's spit out
} catch (Exception e) {
//excluded in example
}
}
public myClass() {
Package pkg = getClass().getPackage();
if (pkg == null)
System.out.println("No Package Found");
else {
System.out.println("specs: " + pkg.getSpecificationTitle() + " - " + pkg.getSpecificationVersion());
System.out.println("imps: " + pkg.getImplementationTitle() + " - " + pkg.getImplementationVersion());
System.out.println("name: " + pkg.getName());
}
//other code here excluded from example
}
}
Output:
specs: null - null
imps: null - null
name: com.example.package1
So what gives? It looks like the pkg object is being defined correctly, but it doesn't read any of the Specification or Implementation properties.