createJavaVM not working pls help

Hello folks,

I am trying to get a simple windows console application to lauch the jvm

but the call to JNI_CreateJavaVM keeps failing (returns -1). I have tried

just about everything (with the paths, client dll, server dll,

paths etc.) but nothing seems to work. I have checked the groups did not

find anything that works for me. Please suggest something, even if you don't

see the problem.

I know that the program does find the jvm.dll, because if i reome it from

the path, the programs complains about not finding the dll (i use the one

from the client directory)

Here is the code (it fails on the call to JNI_CreateJavaVM):

(the call to launching the java class is commented out since i was not get

past the problem of creating the jvm)

This is my code

#include <stdio.h>

#include <jni.h>

JNIEnv* create_vm() {

JavaVM* jvm;

JNIEnv* env;

JavaVMInitArgs args;

JavaVMOption options[1];

int i;

/* There is a new JNI_VERSION_1_4, but it doesn't add anything for the purpo

ses of our example. */

args.version = JNI_VERSION_1_4;

// args.version = 0x30010024;

args.nOptions = 1;

options[0].optionString = "-Djava.class.path=c:\\users\\kabilesh\\javacheck\

\jvm";

args.options = options;

args.ignoreUnrecognized = JNI_TRUE;

printf("inside create vm\n");

i = JNI_CreateJavaVM(&jvm, (void **)&env, &args);

perror("error:");

printf("after create vm : %d\n", i);

switch(i) {

case JNI_OK: printf("success");

break;

case JNI_ERR: printf("unknown error");

break;

case JNI_EDETACHED: printf("thread detached from the VM");

break;

case JNI_EVERSION: printf("JNI version error");;

break;

case JNI_ENOMEM: printf("not enough memory");

break;

case JNI_EEXIST: printf("VM already created");

break;

case JNI_EINVAL: printf("invalid arguments");

break;

}

return env;

}

void invoke_class(JNIEnv* env) {

jclass helloWorldClass;

jmethodID mainMethod;

jobjectArray applicationArgs;

jstring applicationArg0;

printf("inside invoke class\n");

//helloWorldClass = (*env)->FindClass(env, "example/jni/InvocationHelloWorld

");

helloWorldClass = (*env)->FindClass(env, "./InvocationHelloWorld");

printf("before main method \n");

mainMethod = (*env)->GetStaticMethodID(env, helloWorldClass, "main", "([Ljav

a/lang/String;)V");

printf("after main method \n");

applicationArgs = (*env)->NewObjectArray(env, 1, (*env)->FindClass(env, "jav

a/lang/String"), NULL);

applicationArg0 = (*env)->NewStringUTF(env, "From-C-program");

(*env)->SetObjectArrayElement(env, applicationArgs, 0, applicationArg0);

(*env)->CallStaticVoidMethod(env, helloWorldClass, mainMethod, applicationAr

gs);

}

int main(int argc, char **argv) {

JNIEnv* env = create_vm();

printf("inside main\n");

invoke_class( env );

printf("after invoke class");

}

os- windows xp

C:/users/kabilesh/javacheck/c2javacheck> java -version

java version "1.5.0"

Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)

Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)

C:/users/kabilesh/javacheck/c2javacheck>

C:/users/kabilesh/javacheck/c2javacheck> jview

Microsoft (R) Command-line Loader for Java Version 5.00.3810

Copyright (C) Microsoft Corp 1996-2000. All rights reserved.

Usage: JView [options] <classname> [arguments]

Options:

/?displays usage text

/cp <classpath>set class path

/cp:p <path>prepend path to class path

/cp:a <path>append path to class path

/n <namespace>namespace in which to run

/ppauses before terminating if an error occurs

/vverify all classes

/d:<name>=<value> define system property

/aexecute AppletViewer

/vstprint verbose stack traces (requires debug classes)

/prof[:options]enable profiling (/prof:? for help)

Classname:

.CLASS file to be executed.

Arguments:

command-line arguments to be passed on to the class file

C:/users/kabilesh/javacheck/c2javacheck>

can you please let me know what should i do to make it run.

thanks

kabilesh

[4566 byte] By [kabilesh] at [2007-9-30 21:27:02]
# 1
Use formatting tags when you post code.... http://forum.java.sun.com/features.jsp#FormattingAnd search this forum for examples that work.... http://forum.java.sun.com/forum.jsp?forum=52
jschell at 2007-7-7 2:58:57 > top of Java-index,Administration Tools,Sun Connection...