本文介绍了JVM不会使用JNI从环境变量类路径加载jar文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请考虑以下代码.
JavaVM * jvm;
JNIEnv *env;
JavaVMInitArgs vm_args;
JavaVMOption options;
options.optionString ="-Djava.class.path=D:\\Work\\mybytes.jar";
vm_args.version = JNI_VERSION_1_6;
vm_args.nOptions = 1;
vm_args.options = &options;
vm_args.ignoreUnrecognized = 0;
JNI_GetDefaultJavaVMInitArgs(&vm_args);
int ret = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
if(ret >=0)
{
jclass myBytesClass=env->FindClass("MyBytes");
jmethodID myByteConstructor=env->GetMethodID(myBytesClass,"<init>","()V");
myByteObj=env->NewObject(myBytesClass,myByteConstructor,NULL);
char* printBytes=env->GetMethodID(myBytesClass,"printBytes","([B)V");
}
我不希望在Code中使用此语句.
I do not want this statement in Code.
options.optionString =-Djava.class.path = D:\ Work \ mybytes.jar";
我想将此jar文件添加到环境变量的类路径中.但是当我将此jar文件添加到classpath变量时,jvm不会加载此jar文件.我不知道为什么会这样?
I want to add this jar file in classpath in environment variable.but when i add this jar file to classpath variable the jvm does not load this jar file.i do not know why this happen?
推荐答案
JNI_GetDefaultJavaVMInitArgs(&vm_args);
在该行之后移动选项字符串的设置.(认为您实际上可以将其全部删除,所以不再需要它了.)
Move your setting of the option string after that line.(Think you can actually remove it all together, don't think its needed anymore)
这篇关于JVM不会使用JNI从环境变量类路径加载jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!