Exception in Thread "Main" Java.Lang.Unsupportedclassversionerror: a (Unsupported Major.Minor Version 51.0)

How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version

The version number shown describes the version of the JRE the class file is compatible with.

The reported major numbers are:

Java SE 18 = 62,
Java SE 17 = 61,
Java SE 16 = 60,
Java SE 15 = 59,
Java SE 14 = 58,
Java SE 13 = 57,
Java SE 12 = 56,
Java SE 11 = 55,
Java SE 10 = 54,
Java SE 9 = 53,
Java SE 8 = 52,
Java SE 7 = 51,
Java SE 6.0 = 50,
Java SE 5.0 = 49,
JDK 1.4 = 48,
JDK 1.3 = 47,
JDK 1.2 = 46,
JDK 1.1 = 45

(Source: Wikipedia)

To fix the actual problem you should try to either run the Java code with a newer version of Java JRE or specify the target parameter to the Java compiler to instruct the compiler to create code compatible with earlier Java versions.

For example, in order to generate class files compatible with Java 1.4, use the following command line:

javac -target 1.4 HelloWorld.java

With newer versions of the Java compiler you are likely to get a warning about the bootstrap class path not being set. More information about this error is available in a blog post New javac warning for setting an older source without bootclasspath.

Exception in thread main java.lang.UnsupportedClassVersionError: a (Unsupported major.minor version 51.0)

Copy the contents of the PATH settings to a notepad and check if the location for the 1.4.2 comes before that of the 7. If so, remove the path to 1.4.2 in the PATH setting and save it.

After saving and applying "Environment Variables" close and reopen the cmd line. In XP the path does no get reflected in already running programs.

java.lang.UnsupportedClassVersionError Unsupported major.minor version 51.0

java.lang.UnsupportedClassVersionError happens because of a higher JDK during compile time and lower JDK during runtime.

Here's the list of versions:

Java SE 9 = 53,
Java SE 8 = 52,
Java SE 7 = 51,
Java SE 6.0 = 50,
Java SE 5.0 = 49,
JDK 1.4 = 48,
JDK 1.3 = 47,
JDK 1.2 = 46,
JDK 1.1 = 45

Exception in thread “main” java.lang.UnsupportedClassVersionError:HelloWorldApp

You compiled the .class for one version and tried to run it on an older version.

How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version

Java 6 Unsupported major.minor version 51.0

According to maven website, the last version to support Java 6 is 3.2.5, and 3.3 and up use Java 7. My hunch is that you're using Maven 3.3 or higher, and should either upgrade to Java 7 (and set proper source/target attributes in your pom) or downgrade maven.

mvn -v gives me Unsupported major.minor version 51.0

First of all, the exception is because the library being loaded is too new for the version of Java running. Version 51.0 is Java 7, so mvn must be running with Java 6 or earlier. This is not up for dispute, no matter what you think JAVA_HOME is.

The command mvn is a shell script that executes the mvn Java executable. It's quite short and easily understandable.

You can confirm the version of Java running by inserting

echo "$JAVA_HOME"
echo "$JAVACMD"
"$JAVACMD" -version

just before the line at the end that starts with

exec "$JAVACMD" ....

It's probably going to Apple's version of java in /System/Library, you almost certainly don't have JAVA_HOME set completely correctly.

EDIT

From the comments, it seems that mvn thinks $JAVA_HOME is

/System/Library/Frameworks/JavaVM.framework/Versions/Current‌​JDK/Home 

This is the location of the Apple JDK which is based on Java 1.6. The correct way to fix the issue is to make sure that JAVA_HOME is set correctly in the right .profile or .bash_profile depending on which shell you use.

The following is my .profile with all non mvn related bits removed.

 JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8/Contents/Home
M2_HOME=/usr/local/maven
M2=$M2_HOME/bin
MAVEN_OPTS="-Xmx512M"
export M2_HOME M2 JAVA_HOME MAVEN_OPTS

PATH=$JAVA_HOME/bin:$HOME/bin:$PATH:$M2

EDITOR=vim
export EDITOR


Related Topics



Leave a reply



Submit