Subj : Rhino and JNI To : netscape.public.mozilla.jseng From : Paulo R. Panhoto Date : Thu Jul 08 2004 03:35 pm Hello everyone, I would like to know if anyone has experienced problems with rhino and JNI. I have a Java class that wraps rhino and I would like to use it in both a Java application and a DLL. When I invoke a JVM from my DLL (yet a native executable program, it will be the DLL when stable) I get an access violation when the GC runs. Can I get some help? I am using Visual C++ 6 and j2sdk1.4.2_05 Thanks in advance. Here is the relevant code: Wrapper.cpp ----------------------------------------------------- BOOL WINAPI DllMain(HINSTANCE, DWORD dwReason, LPVOID) { switch(dwReason) { case DLL_PROCESS_ATTACH: { JavaVMInitArgs args = {0}; args.version = JNI_VERSION_1_4; args.nOptions = 3; JavaVMOption options[] = {{"-Djava.class.path=.;c:\\lib\\java\\rhino1_5R5\\js.jar;"}, {"-verbose:gc"}, {"-Xnoclassgc"}}; args.options = options; if(JNI_CreateJavaVM(&jvm, (void **) &env, &args) < 0) return FALSE; } break; case DLL_PROCESS_DETACH: jvm->DestroyJavaVM(); break; } return TRUE; } void WINAPI Init() { jclass obj_class = env->FindClass("Invoker"); jmethodID id = env->GetStaticMethodID(obj_class, "main", "([Ljava/lang/String;)V"); env->CallStaticVoidMethod(obj_class, id); } Invoker.java -------------------------------------------------------- import org.mozilla.javascript.*; class Invoker { public static void main(String[] args) { System.out.println("enter"); Context c = Context.enter(); System.out.println("init"); Scriptable s = c.initStandardObjects(); try { System.out.println("eval"); System.out.println(c.evaluateString(s, "1;", "teste", 0, null)); } catch(Exception e) { e.printStackTrace(); } System.out.println("exit"); Context.exit(); } } .