wood burning stoves 2.0*
The moose likes Other JSE/JEE APIs and the fly likes lingle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "lingle" Watch "lingle" New topic


tong cuiling

Joined: May 14, 2003
Posts: 1
I can't start the jvm from a C++ method, the source code looks like this:

#include <jni.h>
#include <string.h>
#include <stdlib.h>

#ifdef _WIN32
#define PATH_SEPARATOR ';'
#define PATH_SEPARATOR ':'
int main()
JavaVMOption options[2];
JNIEnv *env;
JavaVM *jvm;
JavaVMInitArgs vm_args;
jint status;
jclass cls;
jmethodID mid;
jint square;
jboolean not;

options[1].optionString = "-Djava.class.path=.";
memset(&vm_args, 0, sizeof(vm_args));
vm_args.version = JNI_VERSION_1_4;
vm_args.nOptions = 2;
vm_args.options = options;

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

fprintf(stderr,"Cann't create Java VM\n");
if (status != JNI_ERR)
cls = env->FindClass("Sample2");
if(cls !=0)
{ mid = env->GetStaticMethodID(cls, "intMethod", "(I)I");
if(mid !=0)
{ square = env->CallStaticIntMethod(cls, mid, 5);
printf("Result of intMethod: %d\n", square);
mid = env->GetStaticMethodID(cls, "booleanMethod", "(Z)Z");
if(mid !=0)
{ not = env->CallStaticBooleanMethod(cls, mid, 1);
printf("Result of booleanMethod: %d\n", not);
return 0;
return -1;

the development tool is VC++. the method JNI_CreateJavaVM return -1, why? Thanks!
subject: lingle
Similar Threads
Invoking JVM through C++ code
Creating VM in C
Have anyone try this code?
Please help...I'm dying here.
Here is how to create process and Image APPName.exe file instead of java or javaw