4

I downloaded the latest version of JDK8 for Mac OS X and also installed maven. However, I seem to be having an incompatibility between Java and maven:

myusername$ mvn -version
    Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/maven/cli/MavenCli : Unsupported major.minor version 51.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:401)
        at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:254)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
        at org.codehaus.plexus.classworlds.launcher.Launcher.getMainClass(Launcher.java:144)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:266)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

I am using:

myusername$ javac -version
javac 1.8.0_45

How can I make Java and maven compatible with each other?

Tried instructions from possible duplicate question: Maven Installation OSX Error Unsupported major.minor version 51.0:

myusername$ export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.6.0_65.jdk/Contents/Home
myusername$ mvn -version
Error: JAVA_HOME is not defined correctly.
  We cannot execute /Library/Java/JavaVirtualMachines/jdk1.6.0_65.jdk/Contents/Home/bin/java
Community
  • 1
  • 1
warship
  • 2,924
  • 6
  • 39
  • 65

2 Answers2

8

The JAVA_HOME of 1.6.x Java versions on the Mac is /Library/Java/Home only Java 7 and higher are installed below /Library/Java/JavaVirtualMachines

Execute /usr/libexec/java_home -version 1.8 to get the current 1.8 Java Home. I use export JAVA_HOME=$(/usr/libexec/java_home -version 1.8) to set my correct JAVA_HOME

mp911de
  • 17,546
  • 2
  • 55
  • 95
  • There seems to be a problem with the `/bin/java` stage that it is trying to run – warship Jun 11 '15 at 08:36
  • Execute `/usr/libexec/java_home -version 1.8` to get the current 1.8 Java Home. I use `export JAVA_HOME=$(/usr/libexec/java_home -version 1.8)` to set my correct `JAVA_HOME` – mp911de Jun 11 '15 at 08:37
  • I got it! Thank you!! The issue was that I downloaded Java8 but didn't use that export command to update. There were incompatibilities in the current version of Maven and my old version of Java 1.6. Looks like the latest version of Maven is better suited with JDK8. – warship Jun 11 '15 at 08:39
1

I was getting the same exact error, no matter what JVM target I chose. The solution was to downgrade maven:

brew uninstall maven
brew tap homebrew/versions
brew install maven30
itsmysterybox
  • 2,748
  • 3
  • 21
  • 26
benipsen
  • 493
  • 6
  • 12