It will not create a Java Virtual Machine (JNI)

A simple command line application:

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 "0" breakpoint is never reached. jvm.dll is in the same directory as my command line application.

I don’t understand what happened. Any ideas? Thanks in advance

+4
source share
2 answers

I think that your question will be answered in the Sun JNI FAQ.

TL DR version: do not move the DLL files to install the JVM.

+5
source

In my experience

Cause

Maybe JVM.DLL is in the lower path.

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

and below the folder contains many DLLs needed by the JVM;

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

So, JMV.DLL (which you dynamically link) is trying to find all the DLL in its parent folder (b).

Decision

Do not copy JVM.DLL to the same folder as your .exe !!!! Check the system variable PATH. It must contain paths (a) and (b). If so, perhaps your .exe will succeed.

+2
source

Source: https://habr.com/ru/post/1305916/


All Articles