Published on Dec 15 2011 in Java

Running Java classfile compiled with newer JDK using java binary from older JDK will result in ‘java.lang.UnsupportedClassVersionError: Bad version number in .class file’ error. Each java class file includes info about JDK used for its compilation. See how to get it.

Make sure that your application/classes are compiled with a JDK version lower or equal to the JDK your application server is running with or upgrade JDK for your application server. The upgrade can easily be done with our Java Control Panel (button in cPanel).

Version numbers are as follows:

You can check what JDK was used to compile your class file by running

javap -verbose MyClassFile | grep major

or

hexdump -e '1/1 "%3d"' -n 2 -s 6 MyClassFile.class

To see what JDK is used by your environment run:

echo $JAVA_HOME

or

ps x | grep java

or

java -version

In case of Tomcat the error may not be mentioned in catalina.out. Please also checklocalhost.YYYY-MM-DD.log file.