简体   繁体   English

从C ++进程启动Java进程

[英]Starting a Java process from a C++ process

How can I start a Java application from within a C++ process? 如何从C ++进程中启动Java应用程序?

I don't want to invoke just some parts of the Java application, as could be done with JNI, but actually run the whole Java application. 我不想调用Java应用程序的某些部分,就像使用JNI一样,但实际上运行整个Java应用程序。

Yes, you can follow the steps at this link: http://java.sun.com/docs/books/jni/html/invoke.html 是的,您可以按照以下链接中的步骤操作: http//java.sun.com/docs/books/jni/html/invoke.html

Note that the sample invokes the "main" method of the loaded class so it would be just as if you did something like java -jar app.jar where the manifest in app jar specifies a main class that loads and starts the app. 请注意,该示例调用已加载类的“main”方法,因此就像您执行类似java -jar app.jar的操作,其中app jar中的清单指定了加载和启动应用程序的主类。

Sure, easily: 当然,很容易:

system("java ClassName");

You can certainly get fancier than that, adding environment variables for CLASSPATH or whatever else you need. 你当然可以获得比这更好的,为CLASSPATH或你需要的任何其他东西添加环境变量。 The details of doing so may be moderately system dependent, however. 然而,这样做的细节可能是适度的系统依赖性的。

system("your java command")工作?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM