New Location

My website has moved to http://www.jasonwhaley.com. Please visit there for the latest and only remain here for legacy content.

Monday, June 22, 2009

OSX Java Update Surprise

On Friday of last week I installed Apple's latest Java update to Leopard, Update 4, which gives us 1.6.0_13 of Java. This patches a pretty critical vulnerability in Java that Apple was lagging behind on addressing in their repackaging of Java.

After installing the update, I notice that my version of Java, as reported by `java -version` was a 1.5 version, not 1.6. However, the Java version I set per Java Prefrences.app was indeed 1.6. I did not muck with any of the symlinks found within /System/Library/Frameworks/JavaVM.framework and there certainly wasn't a java bin directory on my path.

Turns out that Java on OSX now honors your JAVA_HOME environmental variable, which I did have set in my .bash_profile file. I originally had this set to Java 1.5 for a project I work on that requires a 1.5 JRE (the bundled version of JAXB in 1.6 conflicts with a version of CXF we depend on).

This is kind of neat actually. I no longer have to open a gui app to change the version of Java I am using... I can use my ~/.bash_profile file as I always have on any other system. Here are the relevant contents of my ~/.bash_profile file:
#export JAVA_HOME=$(/usr/libexec/java_home)
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
#export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Home
I basically leave the version of Java I want to use uncommented and then `source ~/.bash_profile` to make that take effect. If I wanted to actually use the Java version that takes priority via what's set on the Java Preferences.app utility, I would uncomment the first line - /usr/libexec/java_home simply returns the directory of the currently active Java version set by Java Preferences.app. I personally chose to forgo that route since it requires multiple steps and opening that utility instead of just allowing me to simply edit my ~/.bash_profile and re-source it.

1 comment:

waz said...

Always use /usr/libexec/java_home to ensure your settings always work.

% /usr/libexec/java_home -v 1.4
/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Home

Just pass it the version you want to point to. It's almost certain Apple will screw with the actual path in some future release.

-h to see a handful of other useful options