I can't start the jvm from a C++ method, the source code looks like this:
#include <jni.h>
#include <string.h>
#include <stdlib.h>
#ifdef _WIN32
#define PATH_SEPARATOR ';'
#else
#define PATH_SEPARATOR ':'
#endif
int main()
{
JavaVMOption options[2];
JNIEnv *env;
JavaVM *jvm;
JavaVMInitArgs vm_args;
jint status;
jclass cls;
jmethodID mid;
jint square;
jboolean not;
options[0].optionString="-verbose:jni";
options[1].optionString = "-Djava.class.path=.";
memset(&vm_args, 0, sizeof(vm_args));
vm_args.version = JNI_VERSION_1_4;
vm_args.nOptions = 2;
vm_args.options = options;
vm_args.ignoreUnrecognized=JNI_TRUE;
status = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
if(status<0){
fprintf(stderr,"Cann't create
Java VM\n");
exit(1);
}
if (status != JNI_ERR)
{
cls = env->FindClass("Sample2");
if(cls !=0)
{ mid = env->GetStaticMethodID(cls, "intMethod", "(I)I");
if(mid !=0)
{ square = env->CallStaticIntMethod(cls, mid, 5);
printf("Result of intMethod: %d\n", square);
}
mid = env->GetStaticMethodID(cls, "booleanMethod", "(Z)Z");
if(mid !=0)
{ not = env->CallStaticBooleanMethod(cls, mid, 1);
printf("Result of booleanMethod: %d\n", not);
}
}
jvm->DestroyJavaVM();
return 0;
}
else
return -1;
}
notation:
the development tool is VC++. the method JNI_CreateJavaVM return -1, why? Thanks!