简体   繁体   中英

Restart tomcat through a java webapp running on it

I looked at this post ,and they said to use a batch script to restart a tomcat server using a webapp. The issue is that if you use Runtime.exec("batch.bat"), once you do the kill for the tomcat server, the server dies and the runtime dies.

I did a quick test of this by adding some prints to my batch file to be sure:

echo "lol" > file1.txt
net stop tomcatservice
echo "lol2" > file2.txt
net start tomcatservice
echo "lol3" > file3.txt

Only file1 was created as suspected.

Is there a way to do what I want? Is there a way for me to restart the tomcat server on a schedule through code in my webapp?

Create a batch file and write shutdown.bat followed by startup.bat. Call that batch file from your java code using Runtime. It should do the trick for you.

使用Runtime.exec("cmd /c start batch.bat")它会启动一个新进程,以便在服务器停止时不会终止它。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM