On May 10, 2011, at 9:38 AM, email@hidden wrote:
> Afaik, some software trusts on the existence of the environment variable $JAVA_HOME.
> MacOSX 10.6.x doesn't set one per default, JAVA_HOME is empty, is not set (at least on MacOSX 10.6.x since Oct. 2010). What's the reason, that this environment variable is not preset/set at all?
Because a single $JAVA_HOME is not appropriate for all applications which need to use Java. You may also have 3rd party JVMs installed which do not support certain deployment modes (for example, OpenJDK does not support applets or Web Start at this time).
> Instead, the developer and/or user has to set it by himself based on
> `man java_home`
> java_home(1) Mac OS X Developer Tools Manual Page'
> Technical Q&A QA1170
> Important Java Directories on Mac OS X
> saying in prose:
> /usr/libexec/java_home helps users set a $JAVA_HOME in their login rc files, or provides a way for
> command-line Java tools to use the most appropriate JVM which can satisfy a minimum version or archi-
> tecture requirement. The --exec argument can invoke tools in the selected $JAVA_HOME/bin directory,
> which is useful for starting Java command-line tools from launchd plists without hardcoding the full
> path to the Java command-line tool.
> Usage for bash-style shells:
> $ export JAVA_HOME=`/usr/libexec/java_home`
> Usage for csh-style shells:
> % setenv JAVA_HOME `/usr/libexec/java_home`
> Which concrete login rc files does the prose of this man page concrete mean?
> Or, asked the other way round: what is the recommended place to set JAVA_HOME? Globally/systemwide? Or better only in user context? Or both?
We do not recommend $JAVA_HOME to be set globally. If you find it useful to set $JAVA_HOME for your particular user, we encourage you to put it in your ~/.bashrc or ~/.profile. Ideally, this will keep $JAVA_HOME scoped to sub-processes of your shell, and not seep into the general graphical environment of your Mac OS X login session.
> Should it be in
> $HOME/.profile (maybe with sourcing ~/.bashrc)
> or in
> or better in:
> /etc/launchd-user.conf <-- see 'man launchd.conf'. Does this function?
> $HOME/.launchd.conf <-- see 'man launchd.conf'. Does this function?
> What named method and place (setting it systemwide or per user, and if yes, via bash/profile or via launchd) would be the best and recommendable and future-proof for setting JAVA_HOME?
> And what's the reason, that Apple doesn't preset $JAVA_HOME relying on `/usr/libexec/java_home` and placed this query per default in the system at the right place, so that the developer or user doesn't need to do this?
Because a single default setting will not be appropriate for all apps run by all users within the same session. The onus of Java-dependent application is to find Java in it's own way on each platform. On Mac OS X, we provide /usr/libexec/java_home as a rich way to express architecture and version constraints that each app may have (and are not appropriate to impose on other apps).
> Afaik, there does exist a Symlink from /Library/Java/Home pointing to /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home (identically with what `/usr/libexec/java_home` outputs) or whatever JVM the user has set in his Java Preferences.
> And if using/preferring one of the named launchd files (/etc/launchd.conf, /etc/launchd-user.conf or $HOME/.launchd.conf) to define a JAVA_HOME variable, and if, for some reason, it might not be possible to execute `/usr/libexec/java_home` in there, is it then recommended/allowed to define instead a "setenv JAVA_HOME /Library/Java/Home" in the launchd file since /Library/Java/Home always equally is symlinking and pointing to that directory, `/usr/libexec/java_home` is resulting and pointing to? Or is /Library/Java/Home weak, less recommended, deprecated and might or will be removed in the future making `/usr/libexec/java_home` the one and only method dynamically determining the JAVA_HOME path?
The /Library/Java/Home path is a legacy path that was used by some applications prior to the creation of the /usr/libexec/java_home tool. It should not be used in production code.
Using /usr/libexec/java_home is the only supported way to locate JVMs or determine if there is any Java installed or enabled at all. Grubbing around on the file system is always the wrong approach.
If you have any more questions, please ask.
Apple Inc. _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden