I am a software engineer at Google on the Android project and the creator of the Java testing framework TestNG. When I'm not updating this weblog with various software-related posts or speaking at conferences, I am busy snowboarding, playing squash, tennis, golf or volleyball or scuba diving. Cedric is a DZone MVB and is not an employee of DZone and has posted 90 posts at DZone. You can read more from them at their website. View Full User Profile

Verifying the Version of your Java Classes

  • submit to reddit

One of the constraints when you work on fundamental software is that you need to be very careful about the classes that you ship. Not just the code itself, but also the version of the compiler that you used to compile these classes.

Despite all my precautions, I have sometimes accidentally shipped classes that were using a compiler that’s too recent. The latest occurrence of this incident was with TestNG’s Eclipse plug-in. Despite all the settings specifying that the JDK should be 1.5, I ended up with 1.6 classes in the feature jar file. I eventually figured out that when you actually build the update site, Eclipse uses some ant tasks which seem to ignore the Eclipse preferences and which revert to the global environment’s JAVA_HOME.

So I ended up writing a quick script that makes one last check before actually uploading the files to the site, which I thought some people might find interesting:

for i in `find . -name \*class`
v=`od -h $i | head -1 | awk '{print $5}'`
if [ $v != "3100" ]
echo "Class $i has version $v, expected 3100"
exit -1

From http://beust.com/weblog/2011/02/21/verifying-the-version-of-your-java-classes/

Published at DZone with permission of Cedric Beust, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)



Mike P(Okidoky) replied on Tue, 2011/02/22 - 12:50pm

Would it not make sense to a "build server" which contains only the lowest denominator tools and libraries? You could use a virtual machine instead of a full machine as well. ps. 1.5 ? Still ?

Piotr Szarański replied on Wed, 2011/02/23 - 12:26pm

Believe me, just switching from 1.5 to 1.6 (or 6.0) is not a matter of few clicks, fast recompiliation and voila it`s ready, when you`re dealing with many copartners and large deployments (600+ client machines). In such situations you stick to old and well known yet tested technology as long, as you can and programmer`s comfort is the need of second category.

Mike P(Okidoky) replied on Thu, 2011/02/24 - 6:06pm

Sounds like a deployment problem. Distribution is an art form IMO. The lesson is to create a proper deployment mechanism right from the get go. Instead of manually installing on 600+ clients, use something like Webstart for seamless upgrading. Or deploy a kickstart app that pulls in the initial installation and then pull in upgrades later.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.