Java 6 and Maven 2.0.9 on Leopard
by Chris Wash on Nov.19, 2008, under Java
Trying to run through a screencast I’m putting together after upgrading to Leopard, I noticed Maven giving me a strange error when trying to run archetype:generate and realized that Leopard includes its own version of Maven (and Ant) out of the box. The problem is that it’s version 2.0.6, which doesn’t have support for this feature. I then set about trying to upgrade Maven (and in the process, Java) and here is what I uncovered.
First of all, I screwed myself over a bit by customizing my /etc/profile under Tiger; there were changes to this file that came in with Leopard but I can’t see where the updater tried to merge them in at all. There are changes in Leopard to how paths are configured using a script called /etc/path_helper, but I don’t have any of that getting executed. It took me a while to figure out this was the reason my .profile, .bash_profile, etc weren’t getting source’d properly. What I did was pull out all of my updates to /etc/profile and just add in the following:
source ~/.profile
So at least now I have my .profile getting loaded properly. I’d still be interested to see someone’s /etc/profile that works out of the box with the call to /etc/path_helper, but this is all beside the point.
Applying the Java update was painless – it worked fine through the Apple Software Update utility. You can download it here manually if you need to.
Next, you’ll probably notice that Java 6 isn’t enabled by default. This blog will show you how to switch over to 6 using the Java Preferences utility. There is a flaw in the ointment, though – for some reason it appears that it doesn’t switch over all of the symlinks properly. Maven’s startup script gets confused by this in a few steps. You can read more about it in this message (some JIRA comments) from their mailing list. The workaround is to just point your JAVA_HOME directly to the 1.6/Home directory.
You can install the newer version of Maven at this point. I saw this post detailing the instructions, but it was what I expected. Just download the latest version and extract it to where you keep these kinds of things. Then you just have to update your .profile (or .bash_profile) to set up some environmental variables for you. Here’s what I included in my ~/.profile:
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
export M2_HOME=/Java/apache-maven-2.0.9
export M2=$M2_HOME/bin
export PATH=$M2:$PATH
You’ll need to do source ~/.profile or exit out of your terminal and open it up again for the changes to take effect. Once you do you can test to make sure you’re seeing the right version of Maven:
cwash:~ chris$ which mvn
/Java/apache-maven-2.0.9/bin/mvn
You can also check this by doing:
cwash:~ chris$ mvn -v
Maven version: 2.0.9
Java version: 1.6.0_07
OS name: “mac os x” version: “10.5.5″ arch: “x86_64″ Family: “mac”
I guess we can chalk this one up to kicking the tires on Leopard. Hope this makes the process a little less painless for someone else!

November 19th, 2008 on 2:47 pm
Thanks for the tips.
I’m a Linux dev trying to get started working on a mac. It has been a rather frustrating experience and all the tips I can collect help.
I created sysmlinks for the java install to /usr/local/java not only to match my linux system but, to make typing a little easier when I need to spell out the whole path.
Same for Maven, symlinked to /usr/local/maven
November 19th, 2008 on 3:28 pm
No problem - you’ll get settled in soon enough! I am eventually going to symlink things neatly like you.
Here’s the misconfigured Apple symlink:
cwash:~ chris$ ls -la /System/Library/Frameworks/JavaVM.framework/Homelrwxr-xr-x 1 root wheel 24 Nov 19 00:21 /System/Library/Frameworks/JavaVM.framework/Home@ -> Versions/CurrentJDK/Home
cwash:~ chris$ ls -la /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/
lrwxr-xr-x 1 root wheel 5 Nov 19 00:21 /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/@ -> 1.5.0
Hope it helps!
November 21st, 2008 on 4:14 am
Hi Chri,
You writing about problems with maven version 2.0.6, but you can easily install maven 2.0.9 from MacPort without any trouble. I think any developer on Leopard have installed MacPort. When you use macport maven, you dont need set any variables for corectly running of maven.
November 21st, 2008 on 2:00 pm
I was waiting for the three-strike rule on MacPorts. This is strike three.
I’ll have a look!