title: creating a JVM from within a JNI method
body: <p>Is it possible to create a JVM from within a JNI method using the JNI API?</p>
  
  <p>I've tried to do this using the JNI function "JNI_CreateJavaVM()", but it's not working (the function keeps returning a value less than zero).</p>
  
  <p>Here is the basic code I'm using (C++):</p>
  
  <pre><code>JNIEnv *env;
  JavaVM *jvm;
  jint res;
  
  #ifdef JNI_VERSION_1_2
  JavaVMInitArgs vm_args;
  JavaVMOption options[2];
  options[0].optionString =
      "-Djava.class.path=" USER_CLASSPATH;
  options[1].optionString = "-verbose:jni";
  vm_args.version = JNI_VERSION_1_2;
  vm_args.options = options;
  vm_args.nOptions = 2;
  vm_args.ignoreUnrecognized = JNI_TRUE;
  /* Create the Java VM */
  res = JNI_CreateJavaVM(&amp;jvm, (void**)&amp;env, &amp;vm_args);
  
  #else
  
  JDK1_1InitArgs vm_args;
  char classpath[1024];
  vm_args.version = 0x00010001;
  JNI_GetDefaultJavaVMInitArgs(&amp;vm_args);
  /* Append USER_CLASSPATH to the default system class path */
  sprintf(classpath, "%s%c%s",
          vm_args.classpath, PATH_SEPARATOR, USER_CLASSPATH);
  vm_args.classpath = classpath;
  /* Create the Java VM */
  res = JNI_CreateJavaVM(&amp;jvm, &amp;env, &amp;vm_args);
  
  #endif /* JNI_VERSION_1_2 */
  </code></pre>
  
  <p>Where USER_CLASSPATH contains the path to the classes I want to load. After the above code executes, res &lt; 0, indicating that JNI_CreateJavaVM() failed. The code above is part of a native method written in C++ called from Java. Any ideas on how to get this to work?</p>
  
  <p>Thanks.</p>