tags:

views:

1356

answers:

3

The version returned by java -version on the command line will be determined by the link /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK if JAVA_HOME is exported as /Library/Java/Home (which is a link to /System/Library/Frameworks/JavaVM.framework/Home)

The version returned by java -version on the command line will be determined by Java Preferences.app if JAVA_HOME is not set.

I've figured this out through trial and error. I am interested in where this is documented.

I'm not sure if CurretntJDK is safe for the user to change. Java Preferences.app doesn't change it.

+2  A: 

do not change currentJDK, i did and it screwed up my java

+1  A: 

In addition, you should avoid setting JAVA_HOME in your .bashrc/.profile . If it is set, the Java Preferences.app has no effect and

java -version

always returns what it regards as the "default" version (in my case, on Mac OS X Leopard, this is Java 1.5).

boxofrats
A: 

Setting the JAVA_HOME environment variable is the proper way to specify the Java version within a session. You can specify JAVA_HOME in the info.plist file or by creating a loader application that sets the environment variable before launching the application.

Please note that setting JAVA_HOME is generally a bad idea because available versions of Java vary depending on the platform/OS version. For example, only 64-bit Intel Macs have Java 6 with Leopard. Both 32-bit and 64-bit Intel Macs have Java 6 with Snow Leopard.

I've found that if you want to support 32-bit Intel Core Duo Macs that have Tiger or Leopard, the best thing to do is target Java 1.5. The Java 1.6 JRE will run Java 1.5 applications. If you need Java 1.6, then you must demand 64-bit Intel with Leopard or any Intel with Snow Leopard from your users. Mind you, there is SoyLatte which provides a Java 1.6 32-bit alternative for Tiger and Leopard users.

"java -version" does change based on the setting of JAVA_HOME, and, as you noticed, also by Java Preferences.

To sum it up, you shouldn't really set JAVA_HOME unless you're distributing a Java JRE with your application, such as SoyLatte. In that case you know the target version and path will be there. Otherwise, you can't rely on a particular version being provided by the OS.

You can find the documentation on Apple's Developer website here: http://developer.apple.com/mac/library/documentation/Java/Conceptual/Java14Development/01-JavaOverview/JavaOverview.html

Marcus Adams