Using Oracle Java VM in-process on Mac Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Using Oracle Java VM in-process on Mac without wasting too much if your time.

The question is published on by Tutorial Guruji team.

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

then 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.

EDIT: the 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.

Answer

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.

We are here to answer your question about Using Oracle Java VM in-process on Mac - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji