How To Make Java 1.5 The Default On OS X
By Adrian Sutton
I’m getting sick of running around web boards posting this over and over again so I thought I’d post it here to try and get people to stop breaking their OS X systems by following bad advice.
First up, the golden rule:
Never modify anything under /System. Any instructions from anyone but Apple that suggests you do this is wrong.
So if someone tells you to modify the symlinks in /System/Frameworks/JavaVM.framework/Versions don’t. It’s not supported by Apple and it will cause you problems when you install future updates to either Java, the OS or other software.
So how do you do it? It depends on where you want the default to apply.
Default For Applets
To set the default JRE for applets in Safari:
- Open /Applications/Utilities/Java/J2SE 5.0/Java Preferences
- Select J2SE 5.0 from the drop down labelled “Use version:” under the “Applets” heading.
You can’t change the JRE for Internet Explorer, it always uses Java 1.3.
For Mozilla variants, they use Java 1.3 by default but recent nightly builds include the Java Embedding Plugin by default which uses Java 1.5 by default automatically. You can install it in previous versions of Mozilla-based browsers as well by following the instructions on that site.
Default For WebStart Applications and Application Bundles
You can specify the default JRE for WebStart applications and Java application bundles by:
- Open /Applications/Utilities/Java/J2SE 5.0/Java Preferences
- In the “Java Application Runtime Settings” section, drag “J2SE 5.0” above “J2SE 1.4.2”.
Note however that you don’t need to do this if you deploy your application via Java WebStart. Instead for WebStart applications developers should use multiple j2se tags in the resources section of your JNLP file. This approach has been suggested by a number of people on the Java-Dev list, see this post by Greg Guerin (quoting crucial parts of Scott Palmer’s earlier post) for information on how to do it. This has been tested and does work on OS X 10.4 such that it will load your application using Java 1.5 if available or Java 1.4 if 1.5 isn’t installed. You can even specify different sets of jar files to load for different JREs.
Default for Command Line
Just like with every other major OS, which version of Java you get on the command line is controlled by your PATH environment variable. If you have /System/Library/Frameworks/JavaVM.framework/Versions/1.5/Commands on your path before /usr/bin (and any other versions of Java) you will get Java 1.5 when you type “java” and any of the other java commands.
Apple provides documentation on setting the PATH variable, including how to set it automatically for every session. There’s also a ton of information on this around the web for different shells.
Where Can I Find More Information?
There’s a ton of information in the list archives for the Java-Dev list. This post probably misses a number of questions developers have, so I’ll try to update it over time. If there’s something extra you think should be here please drop it into a comment below and I’ll merge the key comments into the main post.