Example #1
0
        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);
        }
Example #2
0
        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);
        }