Skip to content

Instantly share code, notes, and snippets.

@SQiShER
Created May 17, 2012 16:46
Show Gist options
  • Save SQiShER/2720113 to your computer and use it in GitHub Desktop.
Save SQiShER/2720113 to your computer and use it in GitHub Desktop.
Two simple commands to resolve problems with Maven installed via Homebrew
defaults write ~/.MacOSX/environment.plist M2_HOME `brew --prefix maven`/libexec
defaults write ~/.MacOSX/environment.plist M2 `brew --prefix maven`/libexec/bin
@SQiShER
Copy link
Author

SQiShER commented May 17, 2012

When you install Maven via Homebrew, chances are that you run into this error, as soon as you try using it:

Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/plexus/classworlds/launcher/Launcher
Caused by: java.lang.ClassNotFoundException: org.codehaus.plexus.classworlds.launcher.Launcher
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

To fix it, you need to point the M2_HOME environment variable to the libexec directory within the maven installation directory (run brew --prefix maven to see the directory of the currently activated version). Setting the M2 variable isn't necessary, but might help, if the problem persists. The two commands above will automatically set the correct paths in your ~/.MacOSX/environment.plist file and should be run every time you update Maven via Homebrew. In order for the changes to take effect you have to log out and in again or restart your Mac.

Credit goes to digitalsanctum.com for figuring this out.

@rkettelerij
Copy link

Thanks for the tip mate!

@binoybcompany
Copy link

Thank you, This was the only solution that worked.

@sanderson-sfdc
Copy link

Thanks, this really saved me. I also did

export M2=brew --prefix maven/libexec/bin
export M2_HOME=brew --prefix maven/libexec

so that I could use maven in my open shell.

@Anaphase
Copy link

Thanks so much!

@maxmarchuk
Copy link

Thank you! I've been at this for too long. This fixed it

@xiaods
Copy link

xiaods commented Sep 9, 2015

Thanks for your tips. @sanderson-sfdc

@jaamiller
Copy link

...and if like me you got
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/maven/cli/MavenCli : Unsupported major.minor version 51.0

Then you need to set JAVA_HOME (check you are using the correct JDK version in the command):
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home

@hbgwhite
Copy link

Thanks! This just solved my problem!

@shar-kumar
Copy link

I just downloaded maven zip file and extracted to my local folder in mac.
maven commands are not recognized in mac

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment