dcsimg
Creating a new JVM inside a current JVM using JNI
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Friday, June 23, 2006 02:00 PM

Hello, i've created a JNI bridge to create newer VMs as needed in my Java appl. - my bridge class have a native method (called startVM()) that is responsable to construct a new VM instance (as i needed) and call different methods inside a few classes definied in the system (they must run in different VMs) . The problem is that when i run the code in WinXP, the method JNI_CreateJavaVM returns -1. I'm using jdk1.4.2_10 with a VC++ 6.0 sp 5 compiler. This is the chunk of code that creates the new VM: // Just to identify the correct VM version JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {    return JNI_VERSION_1_4; }    More>>

Hello, i've created a JNI bridge to create newer VMs as needed in my Java appl. - my bridge class have a native method (called startVM()) that is responsable to construct a new VM instance (as i needed) and call different methods inside a few classes definied in the system (they must run in different VMs) .

The problem is that when i run the code in WinXP, the method JNI_CreateJavaVM returns -1. I'm using jdk1.4.2_10 with a VC++ 6.0 sp 5 compiler.

This is the chunk of code that creates the new VM:




// Just to identify the correct VM version

JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)

{

   return JNI_VERSION_1_4;

}



/**

* Creates a new Virtual Machine

*/

JNIEnv* create_vm(JNIEnv* currEnv=0, const char* _classpath=0)

{

   JNIEnv* _newEnv;



   JavaVMInitArgs args;

   JavaVMOption options[3];

   classpath = "-Djava.class.path=";

   if (_classpath!=0) classpath.append(_classpath);



   CreateJavaVM_t createVM;

   createVM = (CreateJavaVM_t) GetProcAddress(hinstLib, "JNI_CreateJavaVM");



   if (createVM!=NULL)

   {

      args.version = JNI_VERSION_1_4;

      args.nOptions = 3;

      args.ignoreUnrecognized = JNI_FALSE;



      options[0].optionString = (char*) classpath.c_str();

      options[1].optionString = "-Djava.library.path=../lib";

      options[2].optionString = "-verbose:jni";

      args.options = options;



      int code = createVM(&jvm, (void **)&_newEnv, &args);

//JNI_CreateJavaVM(&jvm, (void **)&env, &args);



      if (_newEnv==NULL || code != 0)

         currEnv->ThrowNew(currEnv->FindClass("org/broker/jesb/BaseException"),

            "Couldn't load the new environment JVM. The new JNIEnv* object is NULL");

      else return _newEnv;

   }

   else

      currEnv->ThrowNew(currEnv->FindClass("org/broker/jesb/BaseException"),

         "Couldn't locate the JNI_CreateJavaVM function inside the jvm.dll libraries");



   // Standard Return //

   return 0;

}


Does anyone knows if it's possible to create a new VM inside another running JVM?




   Tks,

      Joao Rios

   <<Less
About | Sitemap | Contact