12 November 2009

Grrr - What Happened to Java 1.5 on Snow Leopard?!



Just this week I updated to Mac OS X Snow Leopard (10.6.2) only to discover that it removes Java 1.5 entirely - WTF?! I have no idea why Java 1.5 was removed but it was a bad decision. How is it logical that Java 1.3 is reinstalled but Java 1.5 is removed? Anyway, after some searching and a bit of trial and error on my system, here are steps that I had to take to fix this situation:


  1. Download Java for Mac OS X 10.5 Update 4

  2. IMPORTANT!!! Make sure to run the following two commands BEFORE proceeding:

    1. sudo rm /System/Library/Frameworks/JavaVM.framework/Versions/1.5

    2. sudo rm /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0


    This removes the old Java 1.5 sym links to prevent the Java 1.6 directory from being overwritten (very bad)

  3. Using the Finder, locate the JavaForMacOSX10.5Update4.dmg file and double-click on it to mount the disk image

  4. Create a sym link to a missing utility:

    1. sudo ln -s /usr/bin/update_dyld_shared_cache /usr/bin/update_prebinding


    This command fixes a missing sym link in Snow Leopard that is needed by the Pacifist in the next step

  5. Using the Pacifist, open the JavaForMacOSX10.5Update4.pkg file from the mounted disk image

  6. In the Pacifist, navigate to /System/Library/Frameworks/JavaVM.framework/Versions and follow these steps:

    1. Right-click on 1.5 and select 'Install to Default Location'

    2. Right-click on 1.5.0 and select 'Install to Default Location'




After going through these steps, Java 1.5 should now be installed on the system. You can see this by listing the following:


$ ls -l /System/Library/Frameworks/JavaVM.framework/Versions/1.5
lrwxr-xr-x 1 bsnyder staff 5 Nov 12 13:47 /System/Library/Frameworks/JavaVM.framework/Versions/1.5 -> 1.5.0
$ ls -1 /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/
Classes
Commands
Headers
Home
Libraries
Resources




NOTE: Through my travels, I've found that many people have no idea that you could switch between different versions of Java. To make the task of switching extremely easy, grab my friend David's setjdk script and use it to handle this task from the command line. It's a bash script that even supports tab completion. So once the script is set up in your environment, switching between versions of Java is as easy as running the following command to see the available Java versions:

$ setjdk <tab>

Then just choose the version you'd like to use, e.g.:

$ setjdk 1.5
Setting this terminal's JDK to 1.5 ... java version "1.5.0_19"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_19-b02-304)
Java HotSpot(TM) Client VM (build 1.5.0_19-137, mixed mode, sharing)


UPDATE: I had to use the steps above to reinstall the documentation for Java 1.5 as well. I found it in the Java for Mac OS X 10.5 Update 4 Developer Documentation. This placed the appledocs.jar, the doc.jar and the src.jar files into the /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home directory. Then I just expanded the doc.jar file to be able to browse the API docs for Java 1.5 via a browser.