JavaVM *jvm = NULL;
JNIEnv *env = NULL;
JavaVMInitArgs vm_args;
JavaVMOption options[2];
args.nOptions = 2;
args.version = JNI_VERSION_1_6;
options[0].optionString = "-Xmx512m";
options[1].optionString ="-Djava.class.path=test.jar:test2.jar";
args.options = options;
#ifdef FOR_MAC_OS
setenv("JAVA_JVM_VERSION", "1.6",1);
#endif
JNI_CreateJavaVM(&jvm, (void **)&env, &args);
(2) get class & method of class
jclass aClass = (*env)->FindClass(env, "Test");
jmethodID aid = (*env)->GetStaticMethodID(env, aClass,"main","([Ljava/lang/String;)V");
(3) call method of class
jobjectArray applicationArgs;
jstring applicationArg0;
applicationArgs = (*env)->NewObjectArray(env, 1, (*env)->FindClass(env, "java/lang/String"), NULL);
applicationArg0 = (*env)->NewStringUTF(env, "Test");
(*env)->SetObjectArrayElement(env, applicationArgs, 0, applicationArg0);
(*env)->CallStaticVoidMethod(env, aClass, aid, applicationArgs);
沒有留言:
張貼留言