cant create JVM with JNI_CreateJavaVM()
843829Sep 28 2005 — edited Nov 13 2005hi..
i am trying to create a JVM in my C++ code...but everytime i get an output "CAN'T CREATE JVM". there are no errors.i think i need help with the setting.i am using jdk1.3.02.should i use jdk1.1 specifically for this purpose. i am sendin the code with this mail as well.
// Test3.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<stdio.h>
#include "InstantiatedFromC.h"
#define PATH_SEPARATOR ';'
#define USER_CLASSPATH "." /* where Prog.class is */
#define BUFSIZE 80
int main(int argc, char **argv )
{
JNIEnv *env;
JavaVM *jvm;
JDK1_1InitArgs *vm_args;
jint res; jclass cls; jmethodID mid;
jstring jstr;
jobjectArray args;
char classpath[1024];
vm_args = new JDK1_1InitArgs();
vm_args->version = 0x00010001; /* version of vm_args */
/* Get the default initialization arguments and set the class path*/
JNI_GetDefaultJavaVMInitArgs(vm_args);
// Tell the JVM where to find the application class files and classes.zip.
sprintf(classpath, "%s%c%s",vm_args->classpath, PATH_SEPARATOR, USER_CLASSPATH);
printf("this is the classpath : %s", classpath);
vm_args->classpath = classpath;
printf("\n\nthis is vm_args : %s\n",vm_args->classpath);
/* load and initialize a Java VM */
res = JNI_CreateJavaVM(&jvm,(void**)&env,&vm_args);
if (res < 0) {
printf("\n\nCan't create Java VM\n");
}
if(env != NULL)
{
/* invoke the Main.test method using the JNI */
cls = env->FindClass("InstantiatedFromC");
if (cls == 0) {
printf("Can't find Prog class\n");
}
mid = env->GetStaticMethodID(cls, "test", "(I)V");
if (mid == 0) {
printf("Can't find Method\n");
}
env->CallStaticVoidMethod(cls, mid, 100);
/* We are done. */
jvm->DestroyJavaVM();
}
}
i have included jni.h file in the instantiatedfromc.h.
thanks
abc