本文介绍了初始化JNI_CreateJavaVM的第三个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

方法JNI_CreateJavaVM的第三个参数将第三个参数作为JavaVMInitArgs结构.

The third argument of the method JNI_CreateJavaVM takes the third argument as JavaVMInitArgs structure.

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

我该如何初始化?我无法这样做.

How do i initialize this ? I am unable to do so.

JNI_CreateJavaVM的原型:jint JNI_CreateJavaVM(JavaVM **pvm, void **penv, void *vm_args);

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

如何初始化vm_args?

How do i initialize vm_args ?

推荐答案

经过一番讨论,我们得出的结论是您的编译器设置存在问题.

要成功编译并链接JNI_CreateJavaVM,您需要将jvm库添加到链接器中.

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

查看调用API 以下示例可能会说明您需要做什么:

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) ...

这篇关于初始化JNI_CreateJavaVM的第三个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 20:48
查看更多