3

I'm trying to run java code from C using code taken from here. The code that attempts to run JVM is as follows:

JNIEnv *env;
    JavaVMInitArgs vm_args;
    JavaVMOption options;
    options.optionString = "-Djava.class.path=D:\\Java Src\\TestStruct";
    vm_args.version = JNI_VERSION_1_6;
    vm_args.nOptions = 1;
    vm_args.options = &options;
    vm_args.ignoreUnrecognized = 0;

    int ret = JNI_CreateJavaVM(jvm, (void**)&env, &vm_args);

The code compiles fine however, when I try to execute it I get the following error:

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

Looking at this question I used dependency walker to find out which binaries I'm missing. It turns out I'm missing ieshims.dll and wer.dll from my computer which according to this the mentioned dlls are used in vista and above (I'm on XP).
So several questions come to my mind:

  • How do I get rid of this?
  • Why am I getting this error in the first place? Can't I load JVM in XP?

I'm on Windows XP, using Visual Studio 2008, JDK 1.7 installed (tried with 1.6 too).

Community
  • 1
  • 1
atoMerz
  • 7,534
  • 16
  • 61
  • 101

2 Answers2

7

There's a similar question in the discussion thread below the article that you linked.

In there, a user found that the solution is to make sure you have the path to your Java binaries in the PATH environment variable. For example:

PATH = "C:\Program Files\Java\jdk1.6.0_18\jre\bin\client";...
Roger Rowland
  • 25,885
  • 11
  • 72
  • 113
3

There's another way - you can load dynamically jvm.dll from a custom location and set java.library.path variable pointing to the native libs. This way it will not have to depend on system env PATH.

Here's example in other thread:

Creating JVM using JNI in C++ does not return

Community
  • 1
  • 1
Artur Witek
  • 109
  • 2
  • True, but this means I would have to manually load every function I'm working with. Possible, but frustrating isn't it? – atoMerz Sep 27 '13 at 07:21
  • 1
    Remember that you still need a JRE - having that said, you only load the jvm.dll and point a custom location of the JRE(libs). The advantage is that you point the specific JRE location instead of relying on the one located on the PATH. You will not need to load any specific JRE .dll files. – Artur Witek Oct 08 '13 at 12:53