Setting Java Version on Leopard
Today I learned something new about Leopard. On the command line, my default JDK was 1.5. I was about to edit a symlink under /System/Library/Frameworks/JavaVM.framework/Versions to change to 1.6, but instead learned about the Java Preferences app.
In Spotlight, find “Java Preferences” and launch it. Or, find it directly under Applications/Utilities/Java. It looks like this:

Just drag and drop to rearrange items in the lists. The JDK at the top of the list becomes your default.
Ant
While this worked, Ant still used the old Java 1.5. I fixed this by adding a line to ~/.bash_profile:
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
Thanks for the tip, Eric. I hadn’t burrowed that far into /Applications/Utilities. Now that you’ve led the way into changing JVMs, and in light of the recent security flap about Apple’s version, can you tell us more about the available JVMs? Or at least give us a pointer to a good discussion of the subject?
Bill
The latest OS X Java Update (presently a developer preview) handles this better. According to the release notes:
By popular request, there is now a way for developers of server or command-line tools to determine the best available Java version to use. /usr/libexec/java_home prints out the path to the user’s preferred version of Java to stdout, which is designed to be used in the $JAVA_HOME environment variable. Mac OS X still does not pre-set a $JAVA_HOME environment variable for all users, because it’s not possible to know the most appropriate version to use for all users, and all applications which may have very different requirements. /usr/libexec/java_home takes version and architecture arguments which filter out ineligible Java versions. See the –help or java_home man page for more information.
@Eric Quick question. Did you have to add “$JAVA_HOME/bin” to your path as well?
@Smitty I did not, the ant shell script automatically appends the “bin” to $JAVA_HOME