This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic


tong cuiling
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
I agree. Here's the link:
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic