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:
- Download Java for Mac OS X 10.5 Update 4
- IMPORTANT!!! Make sure to run the following two commands BEFORE proceeding:
- sudo rm /System/Library/Frameworks/JavaVM.framework/Versions/1.5
- 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) - Using the Finder, locate the JavaForMacOSX10.5Update4.dmg file and double-click on it to mount the disk image
- Create a sym link to a missing utility:
- 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 - Using the Pacifist, open the JavaForMacOSX10.5Update4.pkg file from the mounted disk image
- Right-click on 1.5 and select 'Install to Default Location'
- Right-click on 1.5.0 and select 'Install to Default Location'
In the Pacifist, navigate to /System/Library/Frameworks/JavaVM.framework/Versions and follow these steps:
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.
Er, there's no Java 1.3 on 10.6 - only 1.6
ReplyDeleteThe hacking you've done to put 1.5 on the system comes highly not recommended from Apple - it's very likely to get broken, possibly taking other Java versions or the whole system with it, in future updates.
The setjdk script is even worse since it's moving around system directories which don't do what the script assumes the do. In particular, CurrentJDK is not, despite the name, guaranteed to always point to the current JDK - it's just around for compatibility with applications that did the wrong thing for Java version detection.
To switch the version of Java you use from the command line, simply adjust your PATH environment variable to point to the right one first, or use the Java Preferences application.
Thanks for the interesting comment, but without solid evidence that I'm stepping into harmful territory for my system, I don't buy it. How can installing an old version of Java take down the entire operating system? Java 1.5 is wholly contained into a single directory. It's not littering files across the filesystem and stomping on other files/directories. Of course, I'd love to be proven wrong in my assumptions.
ReplyDeleteI also understand that there is no guarantee that the CurrentJDK sym link will always point to the current JDK. There's also no guarantee that my system won't boot one day, that's what backups are for. Using this sym link is simply a convenience, but one that I've used since before the setjdk script was created and it has worked quite well. I use this command often enough that I know will know right away if something goes awry.
You should install the Java for Mac OS X 10.6 Update 1 Developer Preview available at connect.apple.com, just to see what the real software update will do to your setup.
ReplyDeleteYou should also not modify the contents of /System/Library/Frameworks, including the CurrentJDK symlink. If you need to get a good value for $JAVA_HOME, use the /usr/libexec/java_home command.
Mike Swingler
Java Runtime Engineer
Apple Inc.
To Mike Swinger:
ReplyDeleteI know it may be a surprise to you but we have to support multiple JDKs. Apple removing a version of JDK that my development efforts and my ability to make living depend on is simply nuts.