6

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?

Andrew
  • 195
  • 2
  • 9

1 Answers1

4

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.

Pavel Zdenek
  • 7,146
  • 1
  • 23
  • 38
  • It's not enough just to set `JAVA_HOME`. In addition path to the `jvm.dll` must be defined (or dll must be just copied). What the difference between client and server version? Do I have only these two DLLs in the system or there are some others? – Andrew Dec 17 '12 at 18:29
  • Client and server are almost the same, only tuned for better performance when used as named. But nothing very bad happens when you use the other one. – Pavel Zdenek Dec 17 '12 at 21:03
  • I don't understand what the solution is. How do we get the C++ program to see jvm.dll to avoid the error in the original question? – Amber Oct 12 '21 at 15:37
  • @Amber there are already much more elaborate answers than mine on SO - first hit https://stackoverflow.com/questions/17305524/simplicity-for-executing-java-from-c – Pavel Zdenek Oct 13 '21 at 20:31