问题
So i need to use jni to call java method. i started with this code :
JNIEnv *env1;
JavaVM** jvm1;
JavaVMInitArgs vm_args1;
JavaVMOption options1[1];
options1[0].optionString = "-Djava.class.path=D:\\Java Src\\TestStruct"; //Path to the java source code
vm_args1.version = JNI_VERSION_1_6; //JDK version. This indicates version 1.6
vm_args1.nOptions = 1;
vm_args1.options = options1;
vm_args1.ignoreUnrecognized = 0;
int reAt = JNI_CreateJavaVM(jvm1, (void**)&env1, &vm_args1);
if(reAt < 0)
Label1->Caption = "failed";
else
Label1->Caption = "Success";
I convert jvm.lib to OMF lib for to use in my builder C++ Application :
COFF2OMF jvm.lib jvm2.lib
I added jvm2.lib to the library path to fixe link error about JNI_CreateJavaVM function.
Now my application compile without error.
But it crash when it call JNI_CreateJavaVM function.
I added the jvm.dll near my .exe
What is the pb in there steps??
How can fixe it?
Thx
回答1:
The first argument to JNI_CreateJavaVM
should be a valid pointer to JavaVM*
:
JavaVM* jvm1;
int reAt = JNI_CreateJavaVM(&jvm1, ...);
In your example, jvm1
is uninitialized.
Consult the documentation for details.
来源:https://stackoverflow.com/questions/25548699/how-to-use-jni-to-start-jvm-in-builder-c-application