Reloading libjvm.so inside JNI_CreateJavaVM
843829Sep 25 2002 — edited Oct 19 2007
Hi all,
I have some code that calls dlopen with the full path of a particular libjvm.so that I want to use. I then pass the "handle" to dlsym in order to get the address of JNI_CreateJavaVM.
This all works fine, and hence I deduce that livjvm.so must be loaded into memory.
Then when I call JNI_CreateJavaVM I get a message saying "Unable to load native library: libjvm.so: cannot open shared object file: No such file or directory".
This makes perfect sense, since my LD_LIBRARY_PATH is purposely not set to anywhere containing a libjvm.so file. I want to be able to read the location of my libjvm.so from a config file, and just dynamically link to it at runtime, without needing to set my LD_LIBRARY_PATH.
This is the important bit: My code is obviously calling JNI_CreateJavaVM from within the libjvm.so that I load with dlopen. So why is JNI_CreateJavaVM then trying to load libjvm.so again?
I've searched through the code for the Java launchers, as contained in src.jar. It seems this is a problem Sun are aware of: they have code that sets the LD_LIBRARY_PATH at runtime and then restarts the process, but I'd rather not have to do this.
Does anyone know why it is JNI_CreateJavaVM tries to reload the jvm library? How can I get round this without having to respawn my process in the same way that the Java launcher does?
Thanks,
Pete Mantell