lil*_*ili 5 java tomcat batch-file
我需要从该 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"
Run Code Online (Sandbox Code Playgroud)
Java代码:
String command = "C:\\Tomcat 7.0\\bin\\restart.bat";
Process p = Runtime.getRuntime().exec(command);
Run Code Online (Sandbox Code Playgroud)
Tomcat 已停止,但未启动。如果我从命令行运行这个批处理,它可以正常工作。
感谢您的时间
这有效:
String fileName = "C:\\Tomcat 7.0\\bin\\restart.bat";
String[] commands = {"cmd", "/c", "start", "\"DummyTitle\"",fileName};
Runtime.getRuntime().exec(commands);
Run Code Online (Sandbox Code Playgroud)
摘自http://www.rgagnon.com/javadetails/java-0014.html
您所要求的并不完全安全和可能,但请查看 Tomcat 管理器 API,它允许您以编程方式操作 Tomcat 部署和实例:
http://tomcat.apache.org/tomcat-7.0-doc/api/index.html
http://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/manager/host/HostManagerServlet.html
| 归档时间: |
|
| 查看次数: |
11730 次 |
| 最近记录: |