dcsimg
Invoke JVM
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Hosni_Saqallah
Posted On:   Wednesday, March 21, 2001 02:28 AM

I have the following code: ---------------------------------- #include "jni.h" //#include "jni_md.h" //#include "HelloWorld.h" void main(int argc, char *argv[], char **envp) { JavaVMOption options[2]; JavaVMInitArgs vm_args; JavaVM *jvm ; JNIEnv *env ; long result=0; jmethodID mid; jfieldID fid; jobject jobj; jclass cls; int i, asize; JavaVMAttachArgs args; //vm_args.version = JNI_VERSION_1_2; options[0].optionString ="-Djava.class.path=D:\JNIPrograms\HelloWorld"; options[1].optionString ="-Djava.compiler=NONE"; //"-Djava   More>>

I have the following code:

			
----------------------------------
#include "jni.h"
//#include "jni_md.h"
//#include "HelloWorld.h"


void main(int argc, char *argv[], char **envp) {
JavaVMOption options[2];
JavaVMInitArgs vm_args;
JavaVM *jvm ;
JNIEnv *env ;
long result=0;
jmethodID mid;
jfieldID fid;
jobject jobj;
jclass cls;
int i, asize;
JavaVMAttachArgs args;

//vm_args.version = JNI_VERSION_1_2;

options[0].optionString ="-Djava.class.path=D:\JNIPrograms\HelloWorld";
options[1].optionString ="-Djava.compiler=NONE";
//"-Djava.class.path=:C:\jdk1.3.0_02\Include";
options[2].optionString = "-Djava.library.path=D:\JNIPrograms\HelloWorld";
options[3].optionString = "-verbose:jni";


/*
options[0].optionString = (char *) "-Djava.class.path=.:C:\jdk1.3.0_02\jre\lib";
options[1].optionString = (char *) "-Djava.compiler=NONE";
vm_args.version = JNI_VERSION_1_2;
vm_args.options = options;
vm_args.nOptions = 2;
vm_args.ignoreUnrecognized = JNI_FALSE;0
*/


vm_args.version = JNI_VERSION_1_2;

vm_args.options = options;
vm_args.nOptions = 4;
vm_args.ignoreUnrecognized = JNI_FALSE;
//args.version=JNI_VERSION_1_2;
//args.name =NULL;
//args.group =NULL;



result = JNI_CreateJavaVM(
&jvm,(void **)&env, &vm_args);


if(result == JNI_ERR ) {
printf("%d",result);
printf("Error invoking the JVM
");
exit (-1);
}

cls = (*env)->FindClass(env,"HelloWorld");
if( cls == NULL ) {
printf("can't find class HelloWorld
");
exit (-1);
}
(*env)->ExceptionClear(env);
mid=(*env)->GetMethodID(env, cls, "writeHello", "()V");
jobj=(*env)->NewObject(env, cls, mid);

(*env)->CallVoidMethod(env,jobj,mid);

(*jvm)->DestroyJavaVM(jvm);

}
----------------------------------

When I try to run this code the "result" varaible is -1, and the JVM is noot loaded.
can u please help me? thanks
Note: I'm using JDK 1.3    <<Less

Re: Invoke JVM

Posted By:   Scott_Sirovy  
Posted On:   Wednesday, April 4, 2001 08:35 AM

The code had this line:



    JavaVMOption options[2];



However, the code fills in 4 options. This is the correct declaration:



    JavaVMOption options[4];



That compiles and creates the JavaVM just fine. Good luck!
About | Sitemap | Contact