I have a crazy request about restarting tomcat server through my webapp. I was searching for nearly 2 days about this and all i found are executing external batch file or calling another program to do it. Is there any optimal solution for this by using java code? Am i missing something?
Asked
Active
Viewed 3,173 times
3 Answers
4
Why not just create a script an call it trough Runtime.exec? Seems quite optimal to me. Since restarting tomcat will terminate the Java VM, it doesn't really make sense to have it as an API call.

Mathias Schwarz
- 7,099
- 23
- 28
-
-
If you only need to have the web-app reloaded (and you don't necessarily need Tomcat itself to restart) you can also update the 'last change' date on web.xml. This will trigger a reload of the web app. You can do that through File#setLastModified. – Mathias Schwarz Mar 23 '12 at 08:09
-
I do need to restart the server, since one of the functions of the WebApp relates to add SSL certificate to the server – Thai Tran Mar 23 '12 at 08:13
2
You can connect to the shutdown port tomcat opens and issue the shutdown command.
See http://tomcat.apache.org/tomcat-7.0-doc/config/server.html

Oded Peer
- 2,377
- 18
- 25
-
1i need to restart the server. There is no way you start the server again if you shutdown it – Thai Tran Mar 23 '12 at 03:15
0
Best solution we have found is to use the Java Service Wrapper
It provides multiple benefits in managing the lifecyle of your server - including what you are trying to achieve - and in particular the ability to easily register as a Windows service.

Bruno Grieder
- 28,128
- 8
- 69
- 101