Initialization of the third argument JNI_CreateJavaVM

The third argument to the method JNI_CreateJavaVMtakes the third argument as a structure JavaVMInitArgs.

typedef struct JavaVMInitArgs { 
                     jint version; 
                     jint nOptions; 
                     JavaVMOption *options; 
                     jboolean ignoreUnrecognized; 
                 } JavaVMInitArgs;

How to initialize this? I can not do it.

JNI_CreateJavaVM prototype :jint JNI_CreateJavaVM(JavaVM **pvm, void **penv, void *vm_args);

How to initialize vm_args?

+1
source share
1 answer

After some discussion, we came to the conclusion that you are having problems configuring the compiler.

To be able to successfully compile and link JNI_CreateJavaVM, you need to add the library jvmto your linker.


Initial answer:

Looking at the Invocation API , the following example might explain what you need to do:

JavaVMInitArgs vm_args;
JavaVMOption options[4];

options[0].optionString = "-Djava.compiler=NONE";           /* disable JIT */
options[1].optionString = "-Djava.class.path=c:\myclasses"; /* user classes */
options[2].optionString = "-Djava.library.path=c:\mylibs";  /* set native library path */
options[3].optionString = "-verbose:jni";                   /* print JNI-related messages */

vm_args.version = JNI_VERSION_1_2;
vm_args.options = options;
vm_args.nOptions = 4;
vm_args.ignoreUnrecognized = TRUE;

/* Note that in the JDK, there is no longer any need to call 
 * JNI_GetDefaultJavaVMInitArgs. 
 */
res = JNI_CreateJavaVM(&vm, (void **)&env, &vm_args);
if (res < 0) ...
+5
source

All Articles