If you have a need to maintain and report a software version number from your code, it is as simple as adding the relevant entry in the archive manifest and using something like:
Package thisPackage = this.getClass().getPackage();
String swVersion = pkg.getImplementationVersion();
No idea why I hadn't spotted that before, but I guess that either the requirement hadn't come up (unlikely) or version numbering may have been maintained using a distinct Java class instead.
Of course, if you don't package in a Java Archive, or don't include the required information in the manifest, this will return a null string, but that is a different subject...
1 comment:
I should also have indicated how you include version number information in the Manifest file.
See java.sun.com/.../packageman.html for details.
And the mismatch between 'thisPackage' and 'pkg' is a deliberate test to see if you are paying attention. Well, it might have been!
Post a Comment