How to start/stop an application from a webapplica

2019-09-03 10:29发布

问题:

I need some help: I have two .war files running on tomcat 7, one is a webapplication, the other one is just a "normal" java application. Now I want to figure out how to start/stop the application from my webapplication. Both applications are on the same tomcat. Operation system is Ubuntu 14.04.

Thanks for your help

回答1:

you can configure that in your server.xml file and put 2 services :

<Service name="app1">
   <Connector port="8081" protocol="org.apache.coyote.http11.Http11NioProtocol" 
           connectionTimeout="20000" 
           redirectPort="8443" />
   <Engine name="Catalina" defaultHost="localhost">
      <Host name="localhost"  appBase="app1"
        unpackWARs="true" autoDeploy="true">
      </Host>
   </Engine>
</Service>
<Service name="app2">
   <Connector port="8082" protocol="org.apache.coyote.http11.Http11NioProtocol" 
           connectionTimeout="20000" 
           redirectPort="8443" />
   <Engine name="Catalina" defaultHost="localhost">
      <Host name="localhost"  appBase="app2"
        unpackWARs="true" autoDeploy="true">
      </Host>
   </Engine>
</Service>

Then the application will run on

  1. app1 on http://localhost:8081
  2. app2 on http://localhost:8082

Resource Link:

  1. Listen Multiple Ports in Tomcat
  2. How to run different apps on single Tomcat instance behind different ports?