OS X Snow Leopard, Java 5, Java 6, and Eclipse
Ninety-nine percent of the Java development that I do is in Eclipse and to date had been with Java 5. A couple of months back I upgraded from OS X Leopard to Snow Leopard. Turns out that the Snow Leopard installer wipes out the Leopard version of Java 5. No big deal, I restored the Leopard JVMs from backup.
Recently, I’ve been working on a web application that requires Java 6. Coincidentally Apple released Java 1.6.0_17 around the same time. It was time to start using the Snow Leopard version of Java 6. However, I still have to support Java 5 applications using Eclipse. So here’s what I did to get Java 5, Java 6, and Eclipse working on OS X Snow Leopard:
- Create a back up of /System/Library/Frameworks/JavaVM.framework.
- Remove the entire /System/Library/Frameworks/JavaVM.framework directory structure.
- Install the OS X 10.6 Java Update 1 as described here at Apple.
- Install the OS X 10.5 Java 5 version described here.
- If you have set a JAVA_HOME environment variable make sure it is unset. I had a JAVA_HOME environment variable set to /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0 and after performing steps 3 and 4 Java 5 would not work until I unset the environment variable.
- Use the OS X Java Preferences app to set your preferred Java order – I set mine to use Java 6 64 bit first, then Java 6 32 bit, then Java 5.
- Now, set up your Eclipse(s) to use Java 5. I have multiple Eclipse versions installed because I work on projects that still use Eclipse 3.4.2 and others that use 3.5. These projects also use different versions of Java as well as different Eclipse and potentially conflicting plugins. So I’ve set up a Java 5 specific Eclipse. To do this edit <your Eclipse installation directory>/Eclipse.appEclipse.app/Contents/MacOS/eclipse.ini.
- In the eclipse.ini file, add a new “-vm” directive like (keep the line feed between “-vm” and the Java 5 location):
-vm
/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0
- Note that some instructions for Eclipse on OS X say to include “/Home/bin” to the “-vm” switch. This never worked for me until I removed the “/Home/bin”.
That’s it. Now when you start that specific Eclipse app it will use Java 5.