0

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 "Tomcat6"

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

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
Rams Kannan
  • 61
  • 1
  • 7

2 Answers2

0

try this

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

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.

Community
  • 1
  • 1
Uriah Carpenter
  • 6,346
  • 30
  • 28