Installing Java 5 back on Snow Leopard (MacOSX 10.6.

x)
Mauricio Hiroshi Nagaoka - 21-Nov-2009

I was trying to build Jetty examples in order to enable Servlet 2.5 annotation processing on Jetty Maven 2 plugin and found out that these examples require Java 5 to build (JDBC classes) and Snow Leopard simply doesn't have it. $ ls -l /System/Library/Frameworks/JavaVM.framework/Versions/ total 48 lrwxr-xr-x 1 root wheel 5 Oct 23 16:51 1.3 -> 1.3.1 drwxr-xr-x 3 root wheel 102 Jul 20 20:35 1.3.1 lrwxr-xr-x 1 root wheel 10 Oct 23 16:51 1.5 -> CurrentJDK lrwxr-xr-x 1 root wheel 10 Oct 23 16:51 1.5.0 -> CurrentJDK lrwxr-xr-x 1 root wheel 5 Oct 23 16:51 1.6 -> 1.6.0 drwxr-xr-x 8 root wheel 272 Oct 29 10:39 1.6.0 drwxr-xr-x 9 root wheel 306 Oct 29 10:39 A lrwxr-xr-x 1 root wheel 1 Oct 23 16:51 Current -> A lrwxr-xr-x 1 root wheel 3 Nov 21 12:17 CurrentJDK -> 1.6 This "how-to" is based on chxo internets', but uses unpkg instead of Pacifist to extract the pkg file and a newer Java update. First, a disclaimer: do it at you own risk. Don't blame me if you mess up your computer. :p - Download Java for Mac OS X 10.5 Update 5 - Mount the dmg file (JavaForMacOSX10.5Update5.dmg) - Unpackage the pkg file (JavaForMacOSX10.5Update5.pkg) on your Desktop - Remove the previous 1.5 and 1.5.0 links from /System/Library/Frameworks/ JavaVM.framework/Versions $ cd /System/Library/Frameworks/JavaVM.framework/Versions $ ls -l 1.5 1.5.0 lrwxr-xr-x 1 root wheel 10 Nov 21 13:57 1.5 -> CurrentJDK lrwxr-xr-x 1 root wheel 10 Nov 21 13:57 1.5.0 -> CurrentJDK $ sudo rm 1.5 1.5.0 - Move the unpackaged 1.5.0 folder from your Desktop to /System/Library/Frameworks/ JavaVM.framework/Versions $ sudo mv ~/Desktop/JavaForMacOSX10.5Update5/System/Library/Frameworks/ JavaVM.framework/Versions/1.5.0 /System/Library/Frameworks/JavaVM.framework/ Versions/1.5.0 - Fix the ownership $ sudo chown -R root:wheel /System/Library/Frameworks/JavaVM.framework/ Versions/1.5.0

- Create the 1.5 link to 1.5.0 $ cd /System/Library/Frameworks/JavaVM.framework/Versions $ sudo ln -s 1.5.0 1.5 - You will end up having something like this: $ ls -l /System/Library/Frameworks/JavaVM.framework/Versions total 40 lrwxr-xr-x 1 root wheel 5 Oct 23 16:51 1.3 -> 1.3.1 drwxr-xr-x 3 root wheel 102 Jul 20 20:35 1.3.1 lrwxr-xr-x 1 root wheel 5 Nov 21 14:08 1.5 -> 1.5.0 drwxr-xr-x 8 root wheel 272 Nov 21 13:53 1.5.0 lrwxr-xr-x 1 root wheel 5 Oct 23 16:51 1.6 -> 1.6.0 drwxr-xr-x 8 root wheel 272 Oct 29 10:39 1.6.0 drwxr-xr-x 9 root wheel 306 Oct 29 10:39 A lrwxr-xr-x 1 root wheel 1 Oct 23 16:51 Current -> A lrwxr-xr-x 1 root wheel 3 Nov 21 13:56 CurrentJDK -> 1.6 - When you open the Java Preferences utiltity (/Applications/Utilities/Java Preferences.app), you should see the Java 1.5 options.

- Unfortunately, the Java Preferences app doesn't affect the java and javac on the command line, but you can use this shell script to easily switch them from 1.6 to 1.5 and vice-versa. I'm copying the script here for convenience. #!/bin/sh cd /System/Library/Frameworks/JavaVM.framework/Versions CURJDK="`readlink CurrentJDK`" echo Current JDK version: $CURJDK if [ "$1" == "" ]; then echo Installed versions: ls exit fi VERFOUND=`ls | grep $1 | head -n 1` if [ "$VERFOUND" != "$1" ]; then BASE="`basename $0`" echo Error: Could not change JDK-- version $1 not installed! echo Run $BASE without arguments to see a list of installed versions. exit 127 fi echo You must now enter your Mac OS X password to change the JDK. sudo ln -fhsv $1 CurrentJDK