Java On Macos

Problems and Solutions

Installing 1.4 or 1.5 on Snow Leopard

Quick Instructions:

  1. Download:
  2. Download Pacifist:
  3. Go to /System/Library/Frameworks/JavaVM.framework/Versions rm both “1.5” and “1.5.0”. Don’t skip this step, because otherwise the extraction will follow the symlinks and overwrite the contents of the 1.6.0 folder, oops.
  4. In Pacifist, drill down into Contents/System/Library/Frameworks/JavaVM.framework/Versions
  5. In Pacifist, select 1.5 and 1.5.0, right-click, and chose Install to Default Location

To switch the default for the system, use the Java Preferences utility (/Applications/Utilities/Java Preferences) or execute the the java command directly (as explained in the Apple Developer Article: Java on Mac OS X Leopard.

Installed Java Tools

  • Common Java tools (ant, maven, junit, derby) are installed here: /usr/share/java.
  • with soft links to /usr/share/
  • where binaries of such are soft linked to /usr/bin/

You can switch which versions by playing with the soft links.

For example, to switch to Ant 1.7:

$ jonamac:share$ pwd
jonamac:share$ sudo rm ant
jonamac:share$ sudo ln -s java/ant-1.7.1 ant

Setting JAVA_HOME on Mac OS


Short answer: /System/Library/Frameworks/JavaVM.framework/


The first thing I needed to do when starting to work with OS X’s Java implementation was set my JAVA_HOME environment variable. Several Java programs use this environment variable to help them locate various JAR files that are not on the default classpath. Since the default Terminal shell on OS X is tcsh, it is easy enough to set your JAVA_HOME to the necessary string as long as you know what that string should be. However, finding the installation directory of Java on OS X was an adventure of its own that led to some interesting questions.
To find the right value that JAVA_HOME should be set to, I first executed a `which java` in the nearest Terminal. this told me that /usr/bin/java was the executable that launched the VM. A quick `ls -l /usr/bin/java` told me that it wasn’t a symbolic link to the JDK installation that I was hoping for. Instead, it is a short shell script that executes:
exec /System/Library/Frameworks/JavaVM.framework/Versions/1.3/Commands/java "$@"
From this bit of information I was able to poke around and find that I could set JAVA_HOME to:
This was all I needed to keep everything happy. But the "Versions/1.3" string intrigued me a little bit, so I dug a bit deeper into the directory structure of the framework and actually found that I could us a shorter string:
To solve this problem forevermore, I dropped the following line into my ~/.login file:

setenv JAVA_HOME /System/Library/Frameworks/JavaVM.framework/Home
Now that I had a solution to the problem at hand, I really wanted to know more about how frameworks were implemented under OS X. After all, everything from AppKit to Cocoa and Carbon to OpenGL is contained in the /System/Library/Frameworks folder. I found the answer in Apple’s "Inside Mac OS X: System Overview". In short, a framework is a type of bundle that packages shared libraries along with resources. In addition, frameworks are versioned which should help developers address compatibility problems as OS X evolves.
After wrapping my head around frameworks for a while, I dug into the other kinds of bundles that exist in OS X, including application bundles. It turns out that items that look like single file applications in the Finder are actually hierarchically structured directories containing the program and its resources. I’ll talk more about how you can package up Java applications into these bundles in a future weblog.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License