Java : Unsupported major.minor version 51.0
By:Roy.LiuLast updated:2019-08-17
1. Problem
Run a “jar” on Debian 7.5, and hits the following error messages :
$ java -jar ripecrawler.jar Exception in thread "main" java.lang.UnsupportedClassVersionError: com/mkyong/whois/job/RipeCrawlJob : Unsupported major.minor version 51.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:643) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:277) at java.net.URLClassLoader.access$000(URLClassLoader.java:73) at java.net.URLClassLoader$1.run(URLClassLoader.java:212) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:205) at java.lang.ClassLoader.loadClass(ClassLoader.java:323) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294) at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
A quick check on the Java version, shows the Debian is using 1.6
$ java -version java version "1.6.0_31" OpenJDK Runtime Environment (IcedTea6 1.13.3) (6b31-1.13.3-1~deb7u1) OpenJDK 64-Bit Server VM (build 23.25-b01, mixed mode)
2. Reason
This is because the “jar” is compiled with JDK 1.7, but you try to run in a JDK 1.6 environment. Refer to the following Wikipedia Java class reference.
J2SE 8 = 52 (0x34 hex) J2SE 7 = 51 (0x33 hex) J2SE 6.0 = 50 (0x32 hex) J2SE 5.0 = 49 (0x31 hex) JDK 1.4 = 48 (0x30 hex) JDK 1.3 = 47 (0x2F hex) JDK 1.2 = 46 (0x2E hex) JDK 1.1 = 45 (0x2D hex)
P.S major.minor version 51.0 = JDK 1.7 / 7
For example, if you compiled your “jar” with JDK 1.6, and try to run in a JDK 1.5 environment, the error message will change to this :
Unsupported major.minor version 50.0
3. Solution
To fix it, download JDK 7, and change the default JDK from 1.6 to 1.7
3.1 Download and install openjdk-7-jdk
$ sudo apt-get install openjdk-7-jdk openjdk-7-jre
3.2 Change the default Java to 1.7 (Working on Debian like system only).
$ sudo update-alternatives --config java There are 2 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 auto mode 1 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 manual mode 2 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1051 manual mode Press enter to keep the current choice[*], or type selection number: 2 update-alternatives: using /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java to provide /usr/bin/java (java) in manual mode
$ java -version java version "1.7.0_55" OpenJDK Runtime Environment (IcedTea 2.4.7) (7u55-2.4.7-1~deb7u1) OpenJDK 64-Bit Server VM (build 24.51-b03, mixed mode)
Done.
From:一号门
COMMENTS