1

i want to restart my tomcat through my java code/servlet. Is there any way to do so??? ON particular Exception,i want to restart my tomcat

splash
  • 13,037
  • 1
  • 44
  • 67
vivekj011
  • 1,129
  • 3
  • 16
  • 23
  • restart using the same JVM or completly shut-down the JVM and restart using a new one? BTW: Which operating system? – Robert Jun 17 '11 at 11:01

3 Answers3

3

No need to run any application. In my code i m just executing my BATCH file. Here is a code for the same:

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

And following is my 'restart_tomcat.bat' file contains

C:\WINDOWS\system32\net stop TomcatServiceName
C:\WINDOWS\system32\net start TomcatServiceName
exit

vivekj011
  • 1,129
  • 3
  • 16
  • 23
1

may be you should write an external program that will execute the scripts shutdown.sh/startup.sh (CATALINA_HOME/bin) and call it when an exception occurs

BraveHeart
  • 11
  • 2
1

If you have the manager application installed you can use it to stop and start individual deployed applications. Note that you don't want to get an application to ask the manager to stop and then restart itself for obvious reasons. Instead you could have a proxy-manager app which will would accept requests to stop and then restart other apps. Your app would then make requests to the proxy-manager.

Qwerky
  • 18,217
  • 6
  • 44
  • 80