Cannot load JVM

15,970

Solution 1

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";...

Solution 2

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

Share:
15,970
atoMerz
Author by

atoMerz

Stackoverflow CV Linkedin profile

Updated on June 04, 2022

Comments

  • atoMerz
    atoMerz almost 2 years

    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).