Invoking a JVM

Hello!

I've got a java gui and a c++ engine that i need to connect. I would like to be able to, from java, call a native function that will create a c++ object, which in one of its methods, will creates a jvm and calls a java function. Is this possible? Currently, i am getting -1 value for my JNI_CreateJavaVM call.

Also, in C++ I am creating a dll (so that it can be loaded by java). Am I correct when I add jvm.lib? Or do I need to directly load the jvm.dll Thanks!

Here is my where I try to invoke the jvm (I am using Visual C++ and using jdk1.3):

JavaVMInitArgs vm_args;

char *m_classPath;

JavaVMOption cp[2];

cp[0].optionString = "-Djava.class.path=c:\\mypath";

cp[1].optionString = "-Djava.class.path=D:\\myclasses";

vm_args.version = JNI_VERSION_1_2;

vm_args.nOptions = 2;

vm_args.ignoreUnrecognized = TRUE;

vm_args.options = cp;

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

if (ret < 0) {

fprintf(stderr, "Can't create JVM. Error: %ld\n", ret);

}

[1113 byte] By [Scorbs37] at [2007-9-26 3:53:20]
# 1
Yes you are right including jvm.lib on Win32.jvm.dll must be on system path.For better portability among differrent JVMs is bettersolution to load "jvm.dll" dynamically.I can send you simple JvmLoader in C++.Here is my email: pavel.broz@altavista.net
pbroz at 2007-6-29 12:41:28 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2
I don't think you can create a JVM in a process that is already running a JVM.All you can do is get a reference to the existing JVM.
jschell at 2007-6-29 12:41:28 > top of Java-index,Java HotSpot Virtual Machine,Specifications...