This is a followup to this question.
MacOS X has the
java command under
/usr/bin. If one installs the JRE from Oracle, it doesn’t work – claims there’s no Java runtime, and offers to download and install Apple’s runtime. But if you first run
export JAVA_HOME=/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
java works as expected. That’s where Oracle JRE installs itself.
Now I’d like to use the Oracle Java VM in-process, and I can’t – the “You need Java runtime” error message keeps popping up, even with JAVA_HOME being set.
Linking against the
JavaVM framework causes the message on app startup, even before main().
Trying to dynamically load
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/server/libjvm.dylib and invoke
JNI_CreateJavaVM causes the same message during the method call.
java command does it somehow, after all. I’ve poked around with a debugger, it does invoke JNI_CreateJavaVM at some point. I’ve even mimicked the arguments (there’s one extra one,
-Dsun.java.launcher=SUN_STANDARD), it didn’t make any difference.
Found the answer here.
Instead of loading libjvm.dylib, one needs to load
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/lib/jli/libjli.dylib. It exports
JNI_CreateJavaVM, too. Call that one, and it’ll work as expected.
Works even with
JAVA_HOME not being set.
Future warning: Oracle says that since Java 1.9, the browser plugin technology will no longer be supported. With that in mind, Oracle JRE’s home in version 1.9 might not be under
Internet Plug-Ins anymore.