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.
[...] Kudos to Chris who got in touch and we had a chat about it on IM. He too haswritten about this issue! [...]
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
Thanks Lance, I’ll give that a try.
[...] de que isso poderia ser um problema isolado para Mac’s, e esse foi quando encontrei o post do Cyntech falando sobre esse problema e então resolvi falar sobre ele na nossa [...]
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.
Thanks for the post man. Saved me a lot of time!
Thank you very much for posting this, worked like a charm.
IB
Thanks! Such a time saver!
Thanks for the post. I finally could figure out where was my problem.
Thanks, worked perfectly!!
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.
very helpful!
Nice blog, worked perfectly for me too. Thanks.
Thank you, you saved a bunch of my neurons!
Thanks man! I’ve spent the whole day struggling with this issue and your post came as a saver.