It won't create a Java VM (JNI)

2020-03-24 06:25发布

My simple command line app:

int _tmain(int argc, _TCHAR* argv[])
{
 JavaVM *jvm;
 JNIEnv *env;
 JavaVMInitArgs vm_args;
 JavaVMOption options[1];
 options[0].optionString = "-Djava.class.path=."; //Path to the java source code
 vm_args.version = JNI_VERSION_1_6; //JDK version. This indicates version 1.6
 vm_args.nOptions = 1;
 vm_args.options = options;
 vm_args.ignoreUnrecognized = 0;

 jint ret = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
 return 0;
}

gives me:

Error occurred during initialization of VM
Unable to load native library: Can't find dependent libraries

The breakpoint at "return 0" is never reached. jvm.dll resides in same directory as my command line app.

I don't get it what's wrong. Any Ideas? Thanx in advance

2条回答
▲ chillily
2楼-- · 2020-03-24 07:02

I think that your problem is answered by this question in the Sun JNI FAQ.

TL;DR version: Don't move the JVM installation's DLLs.

查看更多
成全新的幸福
3楼-- · 2020-03-24 07:13

In my experiance,

Cause

Maybe, JVM.DLL is located in below path.

C:\Program Files\Java\jdk1.6.0_xx\jre\bin\client\ (a)

and below folder contains many DLLs the JVM needs;

C:\Program Files\Java\jdk1.6.0_xx\jre\bin\ (b)

So, the JMV.DLL (that you dynamically linked) tries to search the all DLLs in its parent folder(b).

Solution

Don't copy JVM.DLL to the same folder in which your .exe is located!!!! Check you PATH system variable. It have to contain (a) and (b) paths. If so, maybe your .exe will be executed successfully.

查看更多
登录 后发表回答