一尘不染

如何从正在运行的Webapp重新启动tomcat?

tomcat

我需要从在此tomcat上运行的Web应用程序重新启动tomcat服务。所以我试图执行脚本来停止tomcat服务,然后启动它:

echo "before stop" >> textfile.txt
NET STOP "Tomcat7"

:loop
    timeout 3
    SC query Tomcat7 | FIND "STATE" | FIND "RUNNING" > NUL

IF ERRORLEVEL 1 (
    goto start
) ELSE (
    goto loop
)

:start
    NET START "Tomcat7"

Java代码:

   String command = "C:\\Tomcat 7.0\\bin\\restart.bat";
   Process p = Runtime.getRuntime().exec(command);

Tomcat已停止,但尚未启动。如果我从命令行运行此批处理,它将正常工作。

感谢您的时间


阅读 510

收藏
2020-06-16

共1个答案

一尘不染

这工作:

        String fileName = "C:\\Tomcat 7.0\\bin\\restart.bat";
        String[] commands = {"cmd", "/c", "start", "\"DummyTitle\"",fileName};
        Runtime.getRuntime().exec(commands);

取自http://www.rgagnon.com/javadetails/java-0014.html

2020-06-16