Java – Unsupported major.minor version 51.0
Run a jar
on Debian 7.5, and hit the following error messages :
Terminal
$ 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 that Debian is using 1.6
Terminal
$ 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)
Solution
Java 7 (major version 51) compiled the jar
file, and we tried to run it in Java 6 (major version 50), and the Java 6 prompts Unsupported major.minor version 51.0.
Note
Refer to this table for a list of the major version of the Java class file.
To fix it, download the Java or JDK 7, and change the default JDK from 6 to 7.
Terminal
$ sudo apt-get install openjdk-7-jdk openjdk-7-jre
Terminal
$ 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
Terminal
$ 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)
Thank you sir, that’s the quicker and better tutorial about this issue.
Good Article..As always very clear and informative..
Also, want to add.. we can always re-compile that Jar with Jdk1.6 and will not run in to this issue.
we can always compile classes with Lower version of java (say 1.6) and run it on Higher version (say 1.7)..and it will run fine.. no issues.. but not other way around (compile with higher version and try to run on lower version).. we will get error..’unsupported major minor version)