Branding build version into manifest and retrieving with Package.getSpecificationVersion
Thu Sep 25 16:14:00 CDT 2008
You would expect this to be straight forward but it isn't quite all there. Even then, there is a slew of bugs in the Sun Java bug parade that are worth looking at.
- the Implementation-XXX and Speicification-XXX must be in a section for the package
- the section name is slash separated and MUST have a trailing slash.
- some of the docs and specs reference Package-XXX but we don't see this "manifesting" itself (nyuck nyuck nyuck).
Here is the example code build.xml for ant
<attribute name="Implementation-Title" value="proof impl" />
<attribute name="Implementation-Version" value="1.2.3" />
<attribute name="Implementation-Vendor" value="implvendor " />
<attribute name="Specification-Title" value="spec title" />
<attribute name="Specification-Version" value="1.2.4" />
<attribute name="Specification-Vendor" value="spec vendor" />
</section>
</manifest>
</jar>
And here is our test class
public class App { public static void main(String[] args){ Package pkg = App.class.getPackage(); System.out.println("Package = " + pkg); System.out.println("Impl:"); System.out.println("Version: " + pkg.getImplementationVersion()); System.out.println("Vendor: " + pkg.getImplementationVendor()); System.out.println("Title: " + pkg.getImplementationTitle()); System.out.println("Spec:"); System.out.println("Version: " + pkg.getSpecificationVersion()); System.out.println("Vendor: " + pkg.getSpecificationVendor()); System.out.println("Title: " + pkg.getSpecificationTitle()); } }
And, the output
Package = package net.skelter.mfproof, spec title, version 1.2.4 Impl: Version: 1.2.3 Vendor: implvendor Title: proof impl Spec: Version: 1.2.4 Vendor: spec vendor Title: spec title