On Feb 20, 2010, at 6:29 AM, René Jansen wrote:
On 15 feb 2010, at 18:00, Mike Swingler wrote:
Just to let you know, the "Important Directories on Mac OS X" Q&A article at <http://developer.apple.com/mac/library/qa/qa2001/qa1170.html> has been updated to recommend using /usr/libexec/java_home to obtain a value to use as $JAVA_HOME. This tool is present as of "Java for Mac OS X 10.5 Update 4", and is built into Mac OS X 10.6.
As a reminder, please never hardcode a path into /System/Library/Frameworks/JavaVM.framework - this directory's structure has undergone subtle changes over time, and will undergo more radical changes in the future. Due to the complex matrix of supported OS versions, JVM architectures and Java versions, it is always best practice to use a dynamic method to obtain a version of Java that works for your program.
Mike,
I currently maintain one of the oldest, if not the oldest, alternative languages on the Java VM, which is NetRexx. I read the article and have some remarks. I am happy to see this method emerge to determine the Java home and I will add it to the platform dependent install docs.
A lot of our users on Mac OSX initially have the problem of getting to a correct classpath. Currently this is the no1 problem on the ibm-netrexx mailing list. Symptoms vary from java.lang.Object not found, to the NetRexx translators classes not found, to the java version of the java compiler not found, for different permutations of people putting the NetRexxC.jar in the extensions directory, having a classpath without '.' or other.
My question is, is the location of classes.jar now going to be constant relative to $JAVA_HOME ? In an unreleased internal IBM version I have an exta entry for /System/Library/Frameworks/JavaVM.framework/Classes/classes.jar built in to assist our MacOSX users, in addition to some support for the IBM JVM on z/Linux where you also need to know where the thing is. Am I to understand that there is a possibility that this changes in the future, and that I better take this out again (or keep adding new versions for the foreseeable future)? Is it allowed to ask for at least a stable path to the classes.jar of at least the currently active Java VM?
On Mac OS X 10.5/10.6 with Java 1.5 and 1.6, you can find classes.jar relative to $JAVA_HOME at "$JAVA_HOME/bundle/Classes/classes.jar".
If you don't have to support 10.4 or Java 1.4, using that path should be forward compatible, as long as you are dynamically finding a $JAVA_HOME. Older Mac JDKs do not contain the "bundle" back-pointing symlink, installed explicitly to help us transition towards a $JAVA_HOME-centric universe.
If for maximum compatibility, you should test for the existence of the following files, and use the first one you find:
$JAVA_HOME/lib/rt.jar
$JAVA_HOME/bundle/Classes/classes.jar
/System/Library/Frameworks/JavaVM.framework/Versions/($VERSION)/Classes/classes.jar
In an ideal world, all of the Mac JRE classes should live inside of a "$JAVA_HOME/lib/rt.jar", like on other platforms. This is actually how the BSD/Mac OpenJDK JVMs are built today. We would like to converge the Apple-distributed JVMs into this form, but there are a number of steps we have to take to get there. In all likelihood, this will be a transition that spans several releases.
Naturally, if/when we create an rt.jar, we will replace classes.jar with a symlink to the new rt.jar, to ensure any legacy code will continue to find it's contents (and a bit more).
I hope this explains our thinking, and helps you better plan ahead,
Mike Swingler
Java Runtime Engineer
Apple Inc.