Reputation: 705
Is there a way to start/stop .war
file from inside another .war
?
I'm running SymmetricDS server using Tomcat 8 (it deploys it's own .war
) and I need to start it, when a button is pressed and Stop likewise. Can I do that?
Upvotes: 3
Views: 519
Reputation: 417642
When a war file is "dropped" into Tomcat's webapp
folder, by default Tomcat automatically deploys it and starts it. When source war file is deleted from the webapp
folder, Tomcat automatically stops and undeploys the webapp.
So basically all you need to do is copy and delete the war file to/from the webapp
folder to start/stop a webapplication.
Also (or if you can't do this) Tomcat has a built-in manager webapplication which is capable to deploy new applications (from war-files), or to stop and undeploy running web applications.
See Manager App HOW-TO for more details on this.
If you want to do this from your code, check out the ManagerServlet
class. You can call it with simple URLs and parameters. The javadoc of the class contains example URLs what you can do with it. Here are 2 important operations specifically to your needs:
/start?path=/xxx
- Start the web application attached to context path /xxx for this virtual host./stop?path=/xxx
- Stop the web application attached to context path /xxx for this virtual host.Upvotes: 3