Unsupported major.minor version 51.0; nested exception is java.lang.UnsupportedClassVersionError


While doing mvn compile i got the following error

Unsupported major.minor version 51.0; nested exception is java.lang.UnsupportedClassVersionError

After going through google links, the error seems to be the JDK version for compilation is different that JDK version executing it .

But when i do , java -version and javac -version , I got the same result .

java version “1.7.0_51”

Java(TM) SE Runtime Environment (build 1.7.0_51-b13)

Then I decided to check java version used by maven and Aha !

frobplant-lm:test hrsht$ mvn -version

Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-14T09:37:52-08:00)

Maven home: /usr/local/Cellar/maven/3.2.1/libexec

Java version: 1.6.0_65, vendor: Apple Inc.

Maven was using java  1.6 and I had java 1.7 in the path.

To fix this I changed the path of maven java version by setting JAVA_HOME to java 1.7 .

Cheers.

How to set the JAVA_HOME variable in Mac OS X – maverick


Here’s what needs to be done:

– Start the Terminal.

$ vi ~/.bash_profile

… and paste the following (make it a single line):

export JAVA_HOME=/System/Library/Frameworks/
JavaVM.framework/Versions/CurrentJDK/Home

this set to java 1.6 or default installed in your mac.

But if you download and install jdk 1.7  which is pointing to /usr/bin/java

Set

export JAVA_HOME=/usr

echo $JAVA_HOME to check the java version

Maven uses JAVA_HOME value for java .

Note: I also tried creating and using the ~/.bashrc file, but that didn’t work (Mac OS 10.6.2), while ~/.bash_profile worked as expected.