示例#1
0
        public static JavaEnvWrapper init(
            JNI_VERSION version     = JNI_VERSION.v1_6,
            string[]       options  = null,
            bool ignoreUnrecognized = false
            )
        {
            IntPtr optionsPtr = IntPtr.Zero;

            if (options != null && options.Length > 0)
            {
                int optSize = Marshal.SizeOf <JavaVMOption>();
                //Leave the trash laying around cause this is a singleton
                //Also cause I don't know when java will try to read these
                optionsPtr = Marshal.AllocHGlobal(optSize * options.Length);
                var optArray = (JavaVMOption *)optionsPtr.ToPointer();
                optArray[1] = new JavaVMOption();
                for (int i = 0; i < options.Length; i++)
                {
                    optArray[i].optionString = Marshal.StringToHGlobalAnsi(options[i]);
                    optArray[i].extraInfo    = IntPtr.Zero;
                }
            }
            var result = new JavaEnvWrapper(
                version: version,
                nOptions: options?.Length ?? 0,
                options: optionsPtr,
                ignoreUnrecognized: (byte)(ignoreUnrecognized ? 1 : 0)
                );

            return(result);
        }
 public void assertJVMLoaded(JavaEnvWrapper env)
 {
     if (env == null)
     {
         throw new InconclusiveException(
                   message: "Java env did not init, marking inconclusive",
                   inner: jvmInitError
                   );
     }
 }
        public void initLibrary()
        {
            JavaEnvWrapper.loadJavaLibrary();

            Assert.IsNotNull(JavaEnvWrapper._JVMLib);
            Assert.AreNotEqual(IntPtr.Zero, JavaEnvWrapper._JVMLib);
            Assert.IsNotNull(JavaEnvWrapper._JNI_CreateJavaVM);

            //Do the jvm init here I guess, but don't check it until later
            try { wrapper = JavaEnvWrapper.init(); }
            catch (Exception e) { this.jvmInitError = e; }
        }