本文介绍了在java程序中执行另一个jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了几个名为A.jar,B.jar的简单java应用程序。现在我想编写一个GUI java程序,以便用户可以按下按钮A执行A.jar,按钮B执行B.jar。此外,我想在GUI程序中输出运行时进程详细信息。有什么建议吗?
I had written several simple java applications named as A.jar, B.jar. Now i want to write a GUI java program so that user can press button A to execute A.jar and button B to execute B.jar .Also i want to output the runtime process detail in my GUI program. Any suggestion?
推荐答案
如果我理解正确你想要在java GUI应用程序内部的单独进程中运行jar 。
If I understand correctly it appears you want to run the jars in a separate process from inside your java GUI application.
为此,你可以使用:
// Run a java app in a separate system process
Process proc = Runtime.getRuntime().exec("java -jar A.jar");
// Then retreive the process output
InputStream in = proc.getInputStream();
InputStream err = proc.getErrorStream();
缓冲流程输出总是很好的做法。
Its always good practice to buffer the output of the process.
这篇关于在java程序中执行另一个jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!