Are you linking against JavaVM.framework? If you just need the JNI headers, 
it's better to use those provided in the JDK (the headers are even correct 
these days...). You shouldn't need to link anything to just open and use 
libjvm. This is generally true for JNI libraries too since native methods are 
dynamically looked up by symbol name. So, instead of "-framework JavaVM" use 
"-I${JDK_HOME}/include -I${JDK_HOME}/include/darwin" and it will find jni.h 
(assuming JDK_HOME is defined and correct).

JLI (libjli) is a much more robust option for 7 and beyond, but the 
documentation around it is sparse. All of our launchers are just wrappers 
around JLI_Launch, it takes a lot of the hassle out of working with libjvm. 
Look in jdk/src/java.base/share/native/launcher/main.c (OpenJDK 9) for an 
example. You will still need to dlopen libjli.dylib and use dlsym to get 
JLI_Launch, it will handle opening libjvm for you.


You could also try the Java Packager, which will go a step further and create a 
native .app bundle for you.

-DrD-

> Hi all,
> 
> I tried to build a very simple launcher (simple c program) for a customer
> to show how to build a java launcher; launcher loads libjvm.dylib using
> dlopen() and resolves JNI_CreateJavaVM via dlsym().
> 
> On MacOS, when running, in JNI_CreateJavaVM I get the same error as
> mentioned in JDK-7131356
> <https://bugs.openjdk.java.net/browse/JDK-7131356> ("No
> Java runtime present, requesting install").
> 
> I was able to work around the issue by locally providing implementations
> for "JLI_MemAlloc" (and, for balance, realloc and free too) and exporting
> them, even though the functions make no sense in the launcher. This symbol
> seems to be a trigger for Apples JavaRuntimeServices framework to stop
> complaining about missing java runtime. I am not even sure this function is
> even called by the Apple framework.
> 
> So my questions are:
> - does anyone know a better workaround?
> - can we hope for a fix?
> 
> Thanks! and Kind Regards,
> 
> Thomas Stüfe

Reply via email to