开发者

Restarting Tomcat service through servlet which is hosted in the same Tomcat

I would like to restart tomcat service on Windows XP, I created a servlet which calls a batch file

public void doGet (HttpServletRequest req, HttpServletResponse res) 
 throws ServletException, IOException  {

      Process p = Runtime.getRuntime().exec("c:\restart_tomcat.bat");
 }

following 2 lines added in my restart_tomcat.bat

   net stop "Tomcat6" 
   net start 开发者_如何学Go"Tomcat6"

requesting the servlet URL stops tomcat server however it isn't started. However when I run batch file restart_tomcat.bat, works fine


try this

Runtime.getRuntime().exec("cmd.exe /c start c:\restart_tomcat.bat");


The process (e.g. restart_tomcat.bat) that is launched by the JVM is likely being killed too when the VM exits so net start never executes. Tomcat uses Commons Daemon which, unfortunately, does not support JVM restarting. (Or I don't how to do it.)

A quick hack: set the service recovery mode to automatically restart.

Longer-term, there are lots of other JVM as a Service options some of which support self-restarting.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜