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.