Maven 2: NoClassDefFoundError: org/codehaus/plexus/classworlds/launcher/Launcher
March 9, 2011 20 Comments
If you were like me and have just installed Apple’s latest Java 6 update and found that Maven 2 doesn’t work, then this might be of some help.
After installing the latest Java update this morning, I returned to what I was working on. I’m working on a community source project at the moment on Github so I usually update and rebuild before continuing my work but I was horrified to get the following error when I tried to run Maven 2:
$ mvn clean install Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/plexus/classworlds/launcher/Launcher
I immediately checked my java version and first discovered that the Apple update had deleted my Java 1.5 install (I require 1.5 for another project I’m on), so that put me in a bad mood to begin with.
Once I’d fixed the java issue, I tried again but nothing had changed. I googled and read newsgroup site after forum site of people getting this problem but the main consistency was that it was an incompatibility between Maven 2 and 3 and the M2_HOME environment variable. I didn’t think this was my problem as I had not installed Maven 3.
Thanks to a good friend of mine, Steve, he directed me to where my MBP thought maven was being run from by using the ‘which’ command.
$ which mvn /usr/bin/mvn
When I investigated this, it revealed something very interesting…
$ ls -la /usr/bin/mvn lrwxr-xr-x 1 root wheel 24 9 Mar 12:09 /usr/bin/mvn -> /usr/share/maven/bin/mvn $ cd /usr/share/ $ ls -la maven lrwxr-xr-x 1 root wheel 16 9 Mar 12:09 maven -> java/maven-3.0.2
It looks like that included with the OSX Java update, it installed maven 3. Now, this is all fine and dandy, but the projects I’m working on don’t run on Maven 3 just yet, so I need to switch this back to my actual Maven 2 install.
$ sudo mv maven maven.temp $ sudo ln -s /opt/apache-maven-2.2.1/ maven $ mvn -version Apache Maven 2.2.1 (r801777; 2009-08-07 05:16:01+1000) Java version: 1.5.0_26 Java home: /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home Default locale: en_US, platform encoding: MacRoman OS name: "mac os x" version: "10.6.6" arch: "i386" Family: "unix"
Working!
Once again, thanks to Steve Swinsburg for his assistance. Make sure you check out his blog for cool development posts.
Pingback: Java update broke my Maven | steveswinsburg
Instead of a symlink, you might just put the maven bin in your path before /usr/bin. As a rule, I don’t like to muck with the default OS X install… e.g.:
export M2_HOME=/usr/local/apache-maven-2.2.1
export PATH=$M2_HOME/bin:$PATH
LikeLike
Thanks Lance, I’ll give that a try.
LikeLike
Pingback: Mac OS X + Downgrade de Maven = Problemas! | Endrigo Antonini
Thanks very much for posting this – it’s just saved me a lot of time. I went for the path option as suggested by Lance.
LikeLike
Thanks for the post man. Saved me a lot of time!
LikeLike
Thank you very much for posting this, worked like a charm.
IB
LikeLike
Thanks! Such a time saver! 🙂
LikeLike
Thanks for the post. I finally could figure out where was my problem.
LikeLike
Thanks, worked perfectly!!
LikeLike
Thanks so much. I was only able to run Maven through Eclipse, which really didn’t make any sense to me. This will make life a lot easier.
LikeLike
very helpful!
LikeLike
Nice blog, worked perfectly for me too. Thanks.
LikeLike
Thank you, you saved a bunch of my neurons!
LikeLike
Thanks man! I’ve spent the whole day struggling with this issue and your post came as a saver.
LikeLike
apple can be an a$$ sometimes
LikeLike
Thank you. I’ve to use cyntech’s idea to find the path where maven is available and use lance option to set the path correctly. It worked
export M2_HOME=/usr/share/java/maven-3.0.4
export PATH=$M2_HOME/bin:$PATH
LikeLike
Thanks a lot! This saved my day.
LikeLike
Thanks for posting this, I got this problem as well.
And then I set MAVEN2_HOME instead of M2_HOME, the issue is gone.
LikeLike
Thanks for this post! I am using Ubuntu 10.04 LTS and was experiencing inconsistent behaviour even after setting correct Maven home variables in PATH. There was a /usr/bin/mvn which was causing problems.
LikeLike