title: Jni java launcher work in c but not in c++
body: <p>I have to make a program that launches a Java application in C++.</p>
  
  <p>The first example in C works fine, it launches the jar perfectly in C. But when I run the same process in C++ I get an exception.</p>
  
  <p>Here is the C code:</p>
  
  <pre><code>SetCurrentDirectoryA("..\\myJavaApp\\");
  JavaVMInitArgs args;
  int optionsLength = 4;
  JavaVMOption options[optionsLength];
  options[0].optionString = "-Djava.class.path=path\\myJar.jar";
  
  options[1].optionString = "-Xbootclasspath/p:.\\lib\\BootJar.jar";
  options[2].optionString = "-Djava.protocol.handler.pkgs=com.protocol";
  options[3].optionString = "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000";
  args.options = options;
  args.ignoreUnrecognized = JNI_FALSE;
  int ret = JNI_CreateJavaVM(&amp;jvm, (void **) &amp;env, &amp;args);
  if (ret &lt; 0) {
      printf("\nUnable to Launch JVM %d ", ret);
  } else {
      printf("\nJVM launched successfully");
  }
  UncaughtExceptionClass = (*env)-&gt;FindClass(env, "mypackage/MyMainClass");
   if (UncaughtExceptionClass == NULL) {
      printf("\nClass not found.");
      (*jvm)-&gt;DetachCurrentThread(jvm);
      return;
  }
  
  mainMethod = (*env)-&gt;GetStaticMethodID(env, UncaughtExceptionClass, "main", "([Ljava/lang/String;)V");
  if (mainMethod == NULL) {
      printf("\nMethod not found.");
      (*jvm)-&gt;DetachCurrentThread(jvm);
      return;
  }
  
  (*env)-&gt;CallStaticVoidMethod(env, UncaughtExceptionClass, mainMethod, NULL);
  
  (*jvm)-&gt;DetachCurrentThread(jvm);
  </code></pre>
  
  <p>and In C++:</p>
  
  <pre><code>SetCurrentDirectoryA(cmdval.c_str());
  JavaVMInitArgs args;
  JavaVMOption options[5];
  std::cout &lt;&lt; " number of argument " &lt;&lt; nbargs &lt;&lt; std::endl;
  
  args.version = JNI_VERSION_1_6;
  args.nOptions = 5;
  options[0].optionString = (char*) "-Djava.class.path=path\\myJar.jar";
  
  
  options[1].optionString = (char*) "-Xbootclasspath/p:.\\lib\\BootJar.jar";
  options[2].optionString = (char*) "-Djava.protocol.handler.pkgs=com.protocol";
  options[3].optionString = (char*) "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000";
  options[4].optionString = "-verbose:jni";
  
  args.options = options;
  args.ignoreUnrecognized = JNI_FALSE;
  int ret = JNI_CreateJavaVM(&amp;jvm, (void **) &amp;env, &amp;args);
  if (ret &lt; 0)
  {
      //        printf("\nUnable to Launch JVM %d ", ret);
  }
  else
  {
      printf("\nJVM launched successfully\n");
  } 
  attachThread = (*jvm).AttachCurrentThread((void**) &amp;env, NULL);
  
  jclass mainClass =(*env).FindClass("mypackage/MyMainClass");
  </code></pre>
  
  <p>Here the exception I get in C++ :</p>
  
  <pre><code>Exception in thread "main" java.lang.NoClassDefFoundError: mypackage/MyMainClass
  Caused by: java.lang.ClassNotFoundException: mypackage.MyMainClass
      at java.net.URLClassLoader$1.run(Unknown Source)
      at java.net.URLClassLoader$1.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
  </code></pre>
  
  <p>Can someone tell me if I am doing something wrong?</p>