Unable to create JVM
Hi !
In my project, i need to call a java method from C code using JNI.
Here is the Java code:
publicclass Prog{
publicstaticvoid main(String args[]){
System.out.println("Hello Java Native"+args[0]);
}
}
And C code:
#include <jni.h>
void destroy (JNIEnv *env,JavaVM *jvm,char *str){.....}
main(){
JNIEnv *env;
JavaVM *jvm;
JavaVMInitArgs vm_args;
JavaVMOption options[3];
....................
options[0].optionString ="-Djava.compiler=NONE";
options[1].optionString ="-Djava.class.path=.";
options[2].optionString ="-verbose:jni";
memset (&vm_args,0,sizeof(vm_args));
vm_args.version = JNI_VERSION_1_4;
vm_args.nOptions = 3;
vm_args.ignoreUnrecognized = JNI_TRUE;
vm_args.options = options;
/* Create Java VM */
res = JNI_CreateJavaVM(&jvm,(void**)&env,&vm_args);
if(res<0){
fprintf(stderr,"Can't create Java VM\n");
printf("%d",res);
exit(1);
}
................................................
(*env) -> CallStaticVoidMethod(env,cls,mid,args);
(*jvm) -> DestroyJavaVM(jvm);
}
I think the code is alright.But when i run it , it tells me "Can't create Java VM".I guess there are some problems with Path or CLASSPATH? And i copy a (jre\bin\client)jvm.dll. Is there something wrong?
Thank you for your help.丠

