title: JNI CallStaticVoidMethod for main does not return to c++
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/4542853/how-to-trap-system-exit-in-code-called-from-jni">How to trap System.exit() in code called from JNI</a>  </p>
  </blockquote>
  
  
  
  <p><code>JNI CallStaticVoidMethod</code> after calling starts the <code>Java</code> process properly but does not return to <code>C++</code> code , it just exit after that.
  My <code>java code</code> does not have have <code>system.exit(0)</code> but it just have <code>return;</code></p>
  
  <pre><code>jclass StringClass = m_JVMEnv-&gt;FindClass("java/lang/String");
      int numOfArguments = (int)m_ServerArguments.size() + 4 ;
      int argumentIndex = 0;
  
      jobjectArray jargs = m_JVMEnv-&gt;NewObjectArray(numOfArguments, StringClass, NULL);    
  
      m_JVMEnv-&gt;SetObjectArrayElement(jargs, argumentIndex++, m_JVMEnv-&gt;NewStringUTF("start"));
  
      std::string strJavaClassPath = "-classpath=";
      strJavaClassPath             += "\"";
      for ( std::size_t idx = 0; idx &lt; m_listOfJars.size() - 1 ; idx++) {
          strJavaClassPath += m_ProductLibDir + "\\lib\\" + m_listOfJars[idx] + ";";
      }
      strJavaClassPath      += m_ProductLibDir + "\\lib\\" + m_listOfJars[m_listOfJars.size() - 1] ;
      strJavaClassPath      += "\"";
  
      m_JVMEnv-&gt;SetObjectArrayElement(jargs, argumentIndex++, m_JVMEnv-&gt;NewStringUTF(strJavaClassPath.c_str()));
  
      for ( std::vector&lt;std::string&gt;::iterator iter = m_ServerArguments.begin(); iter != m_ServerArguments.end(); ++iter) {
          std::string argument = *iter;
          m_JVMEnv-&gt;SetObjectArrayElement(jargs, argumentIndex++, m_JVMEnv-&gt;NewStringUTF(argument.c_str()));
      }
      m_JVMEnv-&gt;SetObjectArrayElement(jargs, argumentIndex, m_JVMEnv-&gt;NewStringUTF("-dir=E:\\Avinash\\personal\\work\\CreateJvm\\Debug"));    
  
      m_JVMEnv-&gt;CallStaticVoidMethod(m_CacheServerLauncherClass, m_MainMethodID, jargs);
  
      std::cout &lt;&lt; "I am done with launching java program" &lt;&lt; std::endl;
      m_RunningJVMInstance-&gt;DestroyJavaVM();
      CheckForJNIException();
  </code></pre>
  
  <p><code>m_JVMEnv-&gt;CallStaticVoidMethod(m_CacheServerLauncherClass, m_MainMethodID, jargs);</code> after this line program control does not return.</p>