Jan 10, 2015; 16:22
Eric Knibbe
Java on Mac OS X
Having just finished wrangling with Java on Mac, I thought I'd share the knowledge I've gained.
Up until OS X Lion, Apple shipped Java as part of the OS. It came in two parts: the JDK for command line tools & software development, and a web browser plugin. Both these components were located inside the /System folder:
/System/Library/Java/Home
--> symlinked to Versions/CurrentJDK/Home
--> symlinked to /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin
--> symlinked to /System/Library/Java/Support/Deploy.bundle/Contents/Resources/JavaPlugin2_NPAPI.plugin
But in 2013, Apple's Java 6 updates disabled the browser plugin by changing the symlink to /System/Library/Java/Support/CoreDeploy.bundle/Contents/JavaAppletPlugin.plugin, whose sole function is to encourage users to download Oracle's plugin instead.
Oracle offers both Java 7 (which will have its last release this year) and Java 8 in JRE or JDK form. Their JRE download is only the browser plugin at /Library/Internet Plug-Ins/JavaAppletPlugin.plugin, while their JDK download is both the plugin (which includes some extra debug info) and the JDK at /Library/Java/JavaVirtualMachines/jdk<version>.jdk. Both installers also add a PrefPane for launching the Java Control Panel, and a launchd item for its auto-updating the miniature version of Java that's inside the browser plugin. (It doesn't touch the JDK, which is why the control panel's reported version might differ from the output of `java -version`, which only checks the JDK.)
Now how do the command line tools know which version is current? That's done by /System/Library/Frameworks/JavaVM.framework, which acts as the proxy between the system and all Java installations. So /usr/bin/java symlinks to /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java, which redirects all calls to the actual binary at /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/bin/java. Since OS X 10.5 the JDK to use is selected by /usr/libexec/java_home, which returns the path to the newest JDK, whether Apple's or Oracle's.
- Up to OS X 10.4, the newest JDK was pointed to by a symlink at /Library/Java/Home.
- `/usr/libexec/java_home --request` generates a prompt to install a JDK if none is found. Up to early Mavericks builds, it offers to install Apple's Java; later versions link to Oracle's download page. However, the old Java prompt is still shown if a program tries to load a Java library (e.g. Lasso), or if that command is run as part of an Installer script. For this reason I added my own prompt to the Lasso 9.3 installer using AppleScript.
- if only Oracle's JRE is installed, /usr/libexec/java_home will fail to find a Java installation, because it doesn't recognize the contents of the plugin as a valid JDK. (If there is a way to make it work as such, I haven't found it, and not for lack of trying...)
- Unlike `java -version`, /usr/libexec/java_home doesn't rely on the JAVA_HOME environment variable, so setting it via the shell or launchd has no effect.
Here's where things get squirrely. Lasso's PDF commands sometimes don't work with Oracle's JDK because it only advertises itself as having the "CommandLine" capability (see /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Info.plist), causing the OS to hunt for another JDK. Things start working if you add "JNI" to its list of capabilities (suggested at <https://github.com/joeferner/node-java/issues/90#issuecomment-45613235> and elsewhere), but will break again if you install a newer JDK later. But, if you have Apple's Java installed, Lasso will use the Oracle JDK without modification! Which brings us to the other fix for this issue: the OS can be fooled into thinking Apple's Java is installed by having empty folders at /System/Library/Java/JavaVirtualMachines/1.6.0.jdk & /System/Library/Java/Support/Deploy.bundle, which for some unknown reason causes the system to allow Lasso to use Oracle's JDK. I've modified the Mac installers to make both changes, so things should still work for Lasso after either a JDK or a system update.
That's about it; I hope this clears up some mysteries for you all.
‐‐‐‐‐‐‐‐‐‐✂‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
Eric3
#############################################################
This message is sent to you because you are subscribed to
the mailing list Lasso Lasso@lists.lassosoft.com
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <Lasso-unsubscribe@lists.lassosoft.com>
Send administrative queries to <Lasso-request@lists.lassosoft.com>