我正在尝试从java应用程序调用java.jar(它通过双击工作)。它正在使用下面的代码。主要问题是当被调用的jar开始工作(一个gui应用程序)时,我无法使用我的主(另一个 gui 应用程序)应用程序。我认为它正在等待 exec 命令的结束。我怎样才能设法正确运行这 2 个应用程序?
public void handle(Event arg0) {
Runtime runTime = Runtime.getRuntime();
try {
Process process = runTime
.exec("java -jar \"D:\\WORKSPACE\\Deploy\\Binary\\XXXX.jar\"");
BufferedInputStream inputStream = new BufferedInputStream(process.getInputStream());
BufferedInputStream errorStream = new BufferedInputStream(process.getErrorStream());
int n1;
byte[] c1 = new byte[4096];
StringBuffer standardOutput = new StringBuffer();
while ((inputStream.read(c1) != -1)) {
standardOutput.append(c1.toString());
}
System.out.println("Standard Output: " + standardOutput.toString());
int n2;
byte[] c2 = new byte[4096];
StringBuffer standardError = new StringBuffer();
while (errorStream.read(c2) != -1) {
standardError.append(c2.toString());
}
System.out.println("Standard Error: " + standardError.toString());
} catch (IOException e) {
e.printStackTrace();
}
}
});