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:
- JDK 1.1 = 45.3
- JDK 1.2 = 46.0
- JDK 1.3 = 47.0
- JDK 1.4 = 48.0
- JDK 1.5 = 49.0
- JDK 1.6 = 50.0
- JDK 1.7 = 51.0
- JDK 1.8 = 52.0
- JDK 9 = 53.0
- JDK 10 = 54.0
- JDK 11 = 55.0
- JDK 12 = 56.0
- JDK 13 = 57.0
- JDK 14 = 58.0
- JDK 15 = 59.0
- JDK 16 = 60.0
- JDK 17 = 61.0
- JDK 18 = 62.0
- JDK 19 = 63.0
- JDK 20 = 64.0
- JDK 21 = 65.0
- JDK 22 = 66.0
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.