Tuesday, March 22, 2011

How to setup JAVA_HOME on Mac OSX


25
down voteaccepted

Does Snow Leopard still have /usr/libexec/java_home? On 10.5, I just set JAVA_HOME to the output of that command, which should give you the Java path specified in your Java preferences. Here's a snippet from my .bashrc file, which sets this variable:

export JAVA_HOME=$(/usr/libexec/java_home)

I haven't experienced any problems with that technique.

(Occasionally I do have to change the value of JAVA_HOME to an earlier version of Java. For example, one program I'm maintaining requires 32-bit Java 5 on OS X, so when using that program, I setJAVA_HOME to /System/Library/Frameworks/JavaVM.framework/Versions/1.5/Home.)

link|edit|flag
Snow Leopard does still have /usr/libexec/java_home. ThanksRobert Christie Aug 28 '09 at 20:40

I tend to use /Library/Java/Home. The way the preferences pane works this should be up to date with your preferred version.

link|edit|flag

Also, it`s interesting to set your PATH to reflect the JDK. After adding JAVA_HOME (which can be done with the example cited by 'mipadi'):

export JAVA_HOME=$(/usr/libexec/java_home)

Add also in ~/.profile:

export PATH=${JAVA_HOME}/bin:$PATH

P.S.: For OSX, I generally use .profile in the HOME dir instead of .bashrc


http://stackoverflow.com/questions/1348842/what-should-i-set-java-home-to-on-osx


No comments: