Load libjvm.so without setting LD_LIBRARY_PATH?
843829Dec 1 2004 — edited Sep 14 2005Hello,
I have a general question. I have an application that makes use of the JNI Invocation
interace, i.e. it loads the jvm dynamically at runtime. I pass the fully qualified path
to the jvm to the library loading function. I load the library, optain the entry
point for the function JNI_CreateJavaVM, set up my arguments and execute it.
On Windows, this always works perfectly.
However, on Linux, I always get the
dreaded "Unable to load native library: libjvm.so: etc"
This happens despite my having set -Djava.home and -Djava.library.path to
the location of libjvm.so.
Reading through this forum, I see that the recommended fix for this problem is
to set my LD_LIBRARY_PATH to point to the directory containing libjvm.so, and
this does indeed correct the problem.
However, for our shipped product, this will not suffice- we want the application to operate independently of how the user's environement is set up.
So,
1) Doesn't anybody know why setting -Djava.library.path does not work?
2) Is there any work around that does not involve LD_LIBRARY_PATH?
Here an except of my code, (it includes some of our company's nonstandard
platform independent code.
#define JVMFUNC "JNI_CreateJavaVM"
typedef jint (JNICALL dllCreateJVM) (JavaVM *pvm, JNIEnv **env, void *args);
dllCreateJVM CreateJVMFromDLL;
..........
.
. Port_String jvmClassPathOpt_("-Djava.class.path=");
jvmClassPathOpt_+=_rendrClassPath;
Port_String jreLibPathOpt_("-Djava.library.path=");
jreLibPathOpt_+=jreLibPath_;
Port_String jreHomeOpt_("-Djava.home=");
jreHomeOpt_+=jvmLoc_;
,........
jvmOptions[0].optionString = "-Djava.compiler=NONE";
jvmOptions[1].optionString = jvmHomeOpt_.GetBuffer;
jvmOptions[2].optionString = jvmClassPathOpt_.GetBuffer();
jvmOptions[3].optionString = jreLibraryPath_GetBuffer();
jvmOptions[4].optionString = "-verbose:gc,jni";
jvmArgs.version = JNI_VERSION_1_2;
jvmArgs.options = jvmOptions;
jvmArgs.nOptions = numJvmArgs;
And later.
jvmDynLib = new PortDynamicLib(jvmLibPath.GetBuffer());
if(!_jvmDynLib->isValid() || !_jvmDynLib->isLoaded()) {
Port_LocError("Could not initialize JVM\n");
return false;
}
CreateJVMFromDLL = (dllCreateJVM) _jvmDynLib->getEntryPoint(JVMFUNC);
jvmRes = CreateJVMFromDLL(&_jvm,&_jvmEnv,&jvmArgs);
In windows at this point things work. In Linux, at this point the program errors out.
Thanks,
CSC