Selecting Java Version – Part 1

Mon, Apr 21

Mac OS X Leopard includes multiple versions of Java in the base install. This can be quite helpful if you need to compile and run Java code across more than one version of the JDK.

You can specify which installed version of Java you prefer to use as the default by tweaking the settings within the Java Preferences application, which is located in the Utilities folder under Java. See the figure below and notice the path reference on the bottom of the figure. The full path is:/Applications/Utilities/Java/

From within the Java Preferences application, in addition to choosing the preferred Java version, there are a number of additional configuration options in the Security and Advanced tabs, with the later tab including a number of options that make it worth a visit.

One last recommendation, if you compile from the command line you can select which version of the Java compiler you are after without having to change the preferred system setting. Open ~/.bash_profile (in your home directory) and create aliases similar to the following:

alias javac-15=/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Commands/java
alias javac-14=/System/Library/Frameworks/JavaVM.framework/Versions/1.4/Commands/java

Check the Java version using the above aliases as follows:

In the second part of this post I’ll show you some of the goings on behind the scenes of the Java configuration on Mac OS X.

One comment

Thanks!!! I have Googled the heck out of this problem, and finally found this page. The solution was so simple. I am trying to compile, package and run a program with Java SE 6, but my Mac was trying to run my .jar file with JDK 1.5. Thanks again!

by Chad on May 18, 2009. #