在jsp页面中执行jar - 等到jar执行完成

时间:2012-05-22 20:04:35

标签: java jsp jar execution

我有一个需要在jsp页面上运行的jar文件。 jar文件旨在在命令行中执行。这是我的代码:

public static String scheduleCourses() throws IOException {

    String execute = "java -jar execute.jar \"jdbc:mysql://localhost:3306/db\" root \"\" file.txt";
    Process process = Runtime.getRuntime().exec(execute);
    BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
    try {
        process.waitFor();
    } catch (InterruptedException ex) {
        Logger.getLogger(widgets.class.getName()).log(Level.SEVERE, null, ex);
        return "Error with import<br>" +ex;
    }
    return "All done";
}

但不知何故,虽然这个函数正在执行,它会在10-20秒内停止。但是如果我从命令提示符运行jar文件 - 它工作得很好

1 个答案:

答案 0 :(得分:0)

我最终得到了上面的解决方案。

相关问题