我需要从jsp页面调用服务器上的外部.jar文件。我首先尝试运行一个简单的java程序来调用jar文件。它在一秒钟内工作。我的代码是:
import java.io.IOException;
public class callJar_2 {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
String jarPath = "C:\\Oyster3.4\\Oyster_v.3.4.13.jar";
String scriptPath = "C:\\Oyster3.4\\IdentityResolutionRunScript.xml";
String args1[] = {"java", "-jar", jarPath, "-r", scriptPath};
ProcessBuilder pb = new ProcessBuilder(args1);
Process p = pb.start();
}
}
然后我尝试在JSP中实现相同的功能。我的代码是:
<%
String s = null;
String jarPath = "C:\\Oyster3.4\\Oyster_v.3.4.13.jar";
String scriptPath = "C:\\Oyster3.4\\IdentityResolutionRunScript.xml";
String args[] = {"java", "-jar", jarPath, "-r", scriptPath};
ProcessBuilder pb = new ProcessBuilder(args);
final Process p = pb.start();
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
// read the output from the command
System.out.println("Here is the standard output of the command:\n");
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
%>
跑步永远不会完成,需要数小时。请帮忙!我怎样才能加快速度?
我也使用runTime.exec()
,但这非常慢。