JNI CallStaticVoidMethod
调用后正确启动Java
进程但不返回C++
代码,然后退出。我的java code
没有,system.exit(0)
但只有return;
jclass StringClass = m_JVMEnv->FindClass("java/lang/String");
int numOfArguments = (int)m_ServerArguments.size() + 4 ;
int argumentIndex = 0;
jobjectArray jargs = m_JVMEnv->NewObjectArray(numOfArguments, StringClass, NULL);
m_JVMEnv->SetObjectArrayElement(jargs, argumentIndex++, m_JVMEnv->NewStringUTF("start"));
std::string strJavaClassPath = "-classpath=";
strJavaClassPath += "\"";
for ( std::size_t idx = 0; idx < 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->SetObjectArrayElement(jargs, argumentIndex++, m_JVMEnv->NewStringUTF(strJavaClassPath.c_str()));
for ( std::vector<std::string>::iterator iter = m_ServerArguments.begin(); iter != m_ServerArguments.end(); ++iter) {
std::string argument = *iter;
m_JVMEnv->SetObjectArrayElement(jargs, argumentIndex++, m_JVMEnv->NewStringUTF(argument.c_str()));
}
m_JVMEnv->SetObjectArrayElement(jargs, argumentIndex, m_JVMEnv->NewStringUTF("-dir=E:\\Avinash\\personal\\work\\CreateJvm\\Debug"));
m_JVMEnv->CallStaticVoidMethod(m_CacheServerLauncherClass, m_MainMethodID, jargs);
std::cout << "I am done with launching java program" << std::endl;
m_RunningJVMInstance->DestroyJavaVM();
CheckForJNIException();
m_JVMEnv->CallStaticVoidMethod(m_CacheServerLauncherClass, m_MainMethodID, jargs);
此行之后程序控制不返回。