Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java. JNI. jvm.dll

I have Visual Studio C++ Project, which has to call some java functionality. I'm going to use JNI. I have specified additional include directories:

C:\Program Files (x86)\Java\jdk1.7.0_10\include

C:\Program Files (x86)\Java\jdk1.7.0_10\include\win32

and additional library directory

C:\Program Files (x86)\Java\jdk1.7.0_10\lib

and was able to compile needed code. But I still cannot run it because of the next error:

The program can't start bacause jvm.dll is missing...

I assume, the simplest way is just to copy the dll into the project directory. But I don't know which one. I found, for example, few different of them:

C:\Program Files (x86)\Java\jdk1.7.0_10\jre\bin\client\jvm.dll

C:\Program Files (x86)\Java\jdk1.7.0_10\jre\bin\server\jvm.dll

C:\Program Files (x86)\Java\jre7\bin\client\jvm.dll

So, which one should I copy?

like image 979
Andrew Avatar asked Dec 16 '12 19:12

Andrew


People also ask

Is JNI part of JVM?

The JNI is a native programming interface. It allows Java code that runs inside a Java Virtual Machine (VM) to interoperate with applications and libraries written in other programming languages, such as C, C++, and assembly.

What is JNI DLL?

On Windows, JNI methods are typically stored in dynamic libraries called Dynamic Link Libraries (DLLs). DLLs contain functions and data, which can be referenced from another load module, for example a dynamic library or an executable program.

What is JNI used for?

JNI is the Java Native Interface. It defines a way for the bytecode that Android compiles from managed code (written in the Java or Kotlin programming languages) to interact with native code (written in C/C++).


1 Answers

You are trying to solve the problem at the wrong end. You are not expected to be copying jvm.dll around, but to set a proper JAVA_HOME environment variable, pointing to either C:\Program Files (x86)\Java\jdk1.7.0_10\ or C:\Program Files (x86)\Java\jre7\. The version of DLL is then selected by java parameter -client or -server (default when no parameter).

Update: now re-reading the question, i see that the scenario is running native program and invoke JVM from it, not (more common) invoking native lib from JVM. In that case, the native program really needs access to jvm.dll. When invoking native lib from JVM, jvm.dll is already preloaded by JVM and the native lib doesn't need to care about it.

like image 134
Pavel Zdenek Avatar answered Oct 26 '22 02:10

Pavel Zdenek