public void TestMethod1() { Setup(); // NO FUNCIONA... ????? JavaVMOption options = new JavaVMOption(); //options.optionString = $@"-Djava.class.path={jdkPath}"; options.optionString = ""; JavaVMInitArgs vm_args = JavaVMInitArgs.create(JNI.JNI_VERSION_1_8, 1); vm_args.set(0, options); int flags; Ref_JavaVM refJavaVM = new Ref_JavaVM(); Ref_JNIEnv refJNIEnv = new Ref_JNIEnv(); flags = JavaVM.CreateJavaVM(refJavaVM, refJNIEnv, vm_args); if (flags == JNI.JNI_ERR) { String msg = "Error creando la maquina virtual"; Debug.WriteLine(msg); throw new Exception(msg); } JNIEnv jniEnv = refJNIEnv.getValue(); JClass clazz = jniEnv.FindClass("java/lang/Object"); Debug.WriteLine("Class " + clazz); }
public void TestMethod1() { Setup(); es.jni.JavaVMOption options = new JavaVMOption(); //options.optionString = $@"-Djava.class.path={jdkPath}"; options.optionString = ""; JavaVMInitArgs vm_args = JavaVMInitArgs.create(JNI.JNI_VERSION_1_8, 1); vm_args.set(0, options); int flags; Ref_JavaVM refJavaVM = new Ref_JavaVM(); Ref_JNIEnv refJNIEnv = new Ref_JNIEnv(); flags = JavaVM.CreateJavaVM(refJavaVM, refJNIEnv, vm_args); if (flags == JNI.JNI_ERR) { String msg = "Error creando la maquina virtual"; Debug.WriteLine(msg); throw new Exception(msg); } JavaVM javaVM = refJavaVM.getValue(); JNIEnv jniEnv = refJNIEnv.getValue(); JClass jclazz = jniEnv.FindClass("java/lang/Object"); Debug.WriteLine("jclazz " + jclazz); GC(jniEnv); JMethodID jinit = jniEnv.GetMethodID(jclazz, "<init>", "()V"); JObject jinstance = jniEnv.NewObject(jclazz, jinit, new JValue[0]); JObject jref = jniEnv.NewGlobalRef(jinstance); Test(jniEnv, jclazz); jniEnv.DeleteLocalRef(jclazz); }
public static int CreateJavaVM(Ref_JavaVM refvm, Ref_JNIEnv refenv, JavaVMInitArgs args) { int ret = JNIPINVOKE.JavaVM_CreateJavaVM(Ref_JavaVM.getCPtr(refvm), Ref_JNIEnv.getCPtr(refenv), JavaVMInitArgs.getCPtr(args)); return(ret); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Ref_JNIEnv obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }