Cannot load JVM

牧云@^-^@ 提交于 2019-12-22 11:14:33

问题


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


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



回答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



来源:https://stackoverflow.com/questions/15873213/cannot-load-jvm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!