Showing posts with label coding. Show all posts
Showing posts with label coding. Show all posts

Wednesday, 19 December 2007

Java Version Numbering

Having developed numerous programs and applications using Java for many years, I was surprised to find a useful feature that had obviously been around for some time.

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...