[Sablevm-user] classpath problems with JNI_CreateJavaVM()
Brought to you by:
egagnon
From: Tom S. <to...@pl...> - 2004-06-28 21:52:06
|
Hello, I am trying to use JNI_CreateJavaVM() to create a JVM, but I am having what I think are classpath problems. The JVM starts ok, but then fails to find my class. Does anyone have any ideas? Versions: gcc 3.3.4-1 The GNU C compiler jikes 1.21-2 Fast Java compiler adhering to language and jikes-sablevm 1.1.0-5 Wrapper for jikes using classes from SableVM sablevm 1.1.0-5 Free implementation of Java Virtual Machine libsablevm1-de 1.1.0-5 Free implementation of JVM secon edition - d Build commands: gcc -lsablevm main.c -o main jikes-sablevm Foo.java Running: $ ./main error finding 'Foo' class $ Test files: /* Foo.java */ public class Foo { public static void main(String args[]) { System.out.println("Foo::main()"); } } /* main.c */ #include <jni.h> #include <stdio.h> int main(int argc, char *argv[]) { JavaVMOption options[1]; JavaVMInitArgs vm_args; JNIEnv *env = NULL; JavaVM *jvm = NULL; jint jni_error; jclass java_class; jmethodID method_id; /* Setup the options list. */ options[0].optionString = "-Djava.class.path=."; options[0].extraInfo = NULL; /* Setup the vm_args structure. */ memset(&vm_args, 0, sizeof(vm_args)); vm_args.version = JNI_VERSION_1_2; vm_args.options = options; vm_args.nOptions = sizeof(options) / sizeof(options[0]); /* Create the Java Virtual Machine. */ jni_error = JNI_CreateJavaVM(&jvm, (void **) &env, &vm_args); if (jni_error < 0) { printf("ERROR: Unable to create JVM, (%i)\n", (int) jni_error); return(1); } /* Get the "Foo" class. */ java_class = (*env)->FindClass(env, "Foo"); if (java_class == NULL) { printf("error finding 'Foo' class\n"); return(1); } /* Get the "main" method ID. */ method_id = (*env)->GetStaticMethodID( env, java_class, "main", "([Ljava/lang/String;)V" ); if (method_id == NULL) { printf("error finding 'main' method\n"); return(1); } /* Call Foo::main(). */ (*env)->CallStaticVoidMethod( env, java_class, method_id, NULL /* args */ ); /* Destroy the VM. */ (*jvm)->DestroyJavaVM(jvm); /* Exit. */ argc = argc; argv = argv; return(0); } -- Tom Schutter (mailto:to...@pl...) Platte River Associates, Inc. (http://www.platte.com) |