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"
Once again, thanks to Steve Swinsburg for his assistance. Make sure you check out his blog for cool development posts.