tags:

views:

129

answers:

3

Trying to get Maven, Java, and OS X to play nice together - something I've done multiple times without issue on Linux and Windows machines. I assumed all I needed to do was download Maven, setup my environment variables and I'd be good. So here's a snippet from my .bash_profile...

export JAVA_HOME=/Library/Java/Home/  
export M2_HOME=/usr/local/apache-maven/apache-maven-2.2.1  
export PATH=$PATH:$M2_HOME/bin

The JAVA_HOME setting is what Apple recommends be used on this Q&A page. Yet after launching a terminal and running mvn --version, here's the output...

Apache Maven 2.2.1 (r801777; 2009-08-06 15:16:01-0400)  
Java version: 1.6.0_17  
Java home: /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home  
Default locale: en_US, platform encoding: MacRoman  
OS name: "mac os x" version: "10.6.2" arch: "x86_64" Family: "mac"

Any idea why the JAVA_HOME I'm setting in my .bash_profile is being ignored by Maven? It's causing problems because things like rt.jar aren't found in the JAVA_HOME Maven is using. I can work around this by creating symbolic links and other hackery in the home Maven is using, but I'd rather have it work correctly since this will just blow up on me the next time Apple pushes a Java update. Thanks for any help...

A: 

well the first thing I would check is whether mvn is a script. If it is you can see how it's sourcing the environment. If it isn't I would look for any config files typically named .mvnrc, or something in /etc. Of course it wouldn't hurt to RTFM!

ennuikiller
It is a script, I can see how this block if [ -z "$JAVA_HOME" ] ; then JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/${JAVA_VERSION}/Home fimight affect things, but when run on it's own the $JAVA_HOME var is set so the if clause is ignored.As for reading the manual, been done. As has searching the Maven user lists. This was my last resort before relying on hack solutions. If you don't have an answer, don't answer.
ian
Apologies for the formatting above...
ian
+2  A: 

On my Mac, /Library/Java/Home is a symlink (actually the start of a chain of symlinks) that ultimately points to /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home. So I don't think maven is ignoring anything. It's just giving you the actual location.

hcayless
+1  A: 

I have the same setup and all works fine. UNSET the "JAVA_HOME" environment variable in your shell script. The Mac install takes care of that. You are setting it wrong anyways.

Unset it, source your file or startup shell and try again.