0

My vitals: OS 10.7.5 Lion, Java version "1.7.0_79", Maven version 3.0.3.

I'm quite new to Environment Variables here, and having a lot of trouble with Maven. I got my current version from Homebrew, but I need a more recent one. I followed snooze92's instructions from this page (Maven Install on Mac OS X) to try to install the latest version of Maven, 3.3.3. My current version, 3.0.3, is stored in /usr/share/java/maven-3.0.3, and there's also a shortcut to that directory at /usr/share/maven.

echo $JAVA_HOME returns /System/Library/Frameworks/JAVAVM.framework/Versions/CurrentJDK/Home.

But running mvn --version returns a bunch of details including: Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre (which is a different folder to the path JAVA_HOME points to.)

Normally, echo $M2_HOME returns nothing. In this case, Maven 3.0.3 works just fine. If I create the $M2_HOME environment variable, as snooze92 suggests, and add it to my path using the following commands:

export M2_HOME=/usr/local/apache-maven/apache-maven-3.3.3
export M2=$M2_HOME/bin
export PATH=$M2:$PATH

Maven stops working; typing in mvn --version returns the following:

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)

Quitting Terminal (or deleting the above lines from my .bash_profile file and re-opening) makes Maven work fine again, although it always reverts to version 3.0.3.

I also tried adding the commands on this page (http://www.mkyong.com/maven/install-maven-on-mac-osx/) to my .bash_profile file:

export M2_HOME=/usr/local/apache-maven/apache-maven-3.3.3
export PATH=$PATH:$M2_HOME/bin

This causes Maven to return the error message:

-Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable and mvn script match.
Community
  • 1
  • 1

1 Answers1

1

You could edit your .bash_profile to export the dynamic path of your JDK 7 Mac OS installation. This can simply be achieved by adding as first line:

export JAVA_HOME=`/usr/libexec/java_home -v 1.7`

Thereby, it should be guaranteed that no 1.6 style JDK (e.g., as delivered by Apple) is used at runtime, but a working JDK 7 of your system environment. Try to validate the output of

java -version

in a new terminal instance after you edited the .bash_profile file. It should give you 1.7.x Java. After this step your newer Maven version should work and can be validated via

mvn -version

Explanation:

If you use /System/Library/Frameworks/JAVAVM.framework/Versions/CurrentJDK/Home instead you will get something like this for your JAVA_HOME:

java version "1.6.0_65" Java(TM) SE Runtime Environment (build 1.6.0_65-b14-466.1-11M4716) Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-466.1, mixed mode)

which is not what you want/need for Maven 3.3.x

Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
MWiesner
  • 8,868
  • 11
  • 36
  • 70