tags:

views:

406

answers:

2

Hello I am trying to create Java Virtual Machine in a cplusplus program using the code as follows:

JNIEnv *env;
JavaVMInitArgs vm_args;
JavaVMOption options[1];
options[0].optionString = "-Djava.class.path=D:\\Java Src\\TestStruct"; //Path to the java source code
vm_args.version = JNI_VERSION_1_6; //JDK version. This indicates version 1.6
vm_args.nOptions = 1;
vm_args.options = options;
vm_args.ignoreUnrecognized = 0;

int ret = JNI_CreateJavaVM(jvm, (void**)&env, &vm_args);
if(ret < 0)
    printf("\nUnable to Launch JVM\n");

I am unable to create an instance as it is giving me the following error . I am able to compile but it is giving runtime error like this..

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

Can anybody help me thanks in advance :)

+2  A: 

Most likely that jvm.dll isn't in your PATH.

Idan K
where to refer the path there are 2 jvm.dll in my jdk folder which i can mention belowC:\Program Files\Java\jdk1.6.0_14\jre\bin\clientC:\Program Files\Java\jdk1.6.0_14\jre\bin\server
Rajesh Kumar J
from what I know it doesn't really matter which one. I usually pick the one under \client.
Idan K
in this folder C:\Program Files\Java\jdk1.6.0_14\lib i am referring jvm.lib in my program settings.
Rajesh Kumar J
try adding C:\Program Files\Java\jdk1.6.0_14\jre\bin\client to your PATH, what happens then?
Idan K
Ya it is working thanks for your help
Rajesh Kumar J