Thursday, January 28, 2010

Find the version number of a .class file

If you see the error:
 java.lang.UnsupportedClassVersionError: Bad version number in .class file
it means that the Java ClassLoader cannot load a certain class because it has been compiled using a different version of the JDK. For example, you might see this error if your application has been compiled using Java 1.5, but an external library you are calling has been compiled using 1.6.

You can use the javap command to find out what the version number of a class file is:

sharfah@starship:~> javap -v MyApp | grep version
  minor version: 0
  major version: 50
50 refers to Java 1.6, while 49 refers to Java 1.5.

1 comment:

  1. Just what I was looking for. Thanks!

    ReplyDelete