Tomcat deploys multiple war packages

Posted by mike97gt on Wed, 15 Apr 2020 04:05:01 +0200

1 Background

System: Window Server.

Installed JDK 1.8-u181 (JRE is enough, but I have the JDK installation package in hand, why not go down) and Tomcat 8.5.53.

Once installed, the environment variable is configured with JAVA_HOME, Path.JRE, no JDK.

To publish two war packages, MES and ERP.

2 Install Tomcat

I used the.exe file installation without tomvat_home (because I didn't know I needed to configure it either)

3 Copy Folder

3.1 Installation directory\conf\Catalina

Catalina is a folder that copies two copies of Catalina, one named CatalinaMES and the other named CatalinaERP, in the installation directory\conf

3.2 Installation Directory\webapps

webapps is also a folder, duplicate two copies, one named webappsMES and the other named webappsERP, all in the installation directory

The war package typed by the MES project is placed in the installation directory\webappsMES

Warpackages typed by ERP projects are placed in the installation directory\webappsERP

4 Modify Profile

Modify the contents of the installation directory\conf\server.xml

<?xml version="1.0" encoding="UTF-8"?>

<Server port="-1" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />

  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />

  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

  <GlobalNamingResources>

    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>

  <!-- deploy mes -->
  <Service name="CatalinaMES">

    <Connector port="8085" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

    <Engine name="CatalinaMES" defaultHost="localhost">

      <Realm className="org.apache.catalina.realm.LockOutRealm">

        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="localhost"  appBase="webappsMES"
            unpackWARs="true" autoDeploy="true">

		    <Context path="/mes-manager-web" docBase="C:\Program Files\Tomcat 8.5\webappsMES\mes-manager-web" debug="0" privileged="true"></Context>

        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>
    </Engine>
  </Service>

  <!-- deploy erp -->
  <Service name="CatalinaERP">

    <Connector port="8082" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

    <Engine name="CatalinaERP" defaultHost="localhost">

      
      <Realm className="org.apache.catalina.realm.LockOutRealm">

        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="localhost"  appBase="webappsERP"
            unpackWARs="true" autoDeploy="true">

		<Context path="/erp-manager-web" docBase="C:\Program Files\Tomcat 8.5\webappsERP\erp-manager-web" debug="0" privileged="true"></Context>


        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>
    </Engine>
  </Service>
</Server>

A node represents a service, that is, a deployed project.

The name property of the node is changed to the name of the corresponding Catalina folder.The name attribute of the node is also changed to the name of the corresponding Catalina folder.

The port property of the node is the port number of the project. Be careful not to conflict.

The appBase property of the node was changed to the corresponding webapps folder.

The path property of the node is the address at which it is accessed, that is, the access address of the project is the value of the server ip: project port number/path property.Based on the current configuration, the native access address for my MES project is 127.0.0.1:8085/mes-manager-web.The docBase property of the node is the local path of the project war package, as long as it is modified to the absolute path of the war package locally.

5 Modify startup.bat and shutdown.bat

Edit the installation directory\bin\startup.bat, with:

SET JAVA_HOME=C:\Program Files\Java\jre1.8.0_181
SET TOMCAT_HOME=C:\Program Files\Tomcat 8.5

The first is the JRE installation location, and the second is the tomcat installation path.

Add the same content to shutdown.bat in the same place.

6 Double-click startup.bat to run tomcat

Note that this will open a dos window, which will print the project startup information like IDEA's console. When the project starts successfully, do not close the dos window, keep it open. If you turn off tomcat, it will stop running

7 Notes

If multiple projects use the spring framework, errors may occur when configuring a tomcat multiport multiapplication.

Solution: Add the following nodes to each project's web.xml:

<context-param>
    <param-name>webAppRootKey</param-name>
    <param-value>webapp.root</param-value>
</context-param>

Ensure that each project's web.xml corresponds to a different webAppRootKey.For example, the first uses webapp.root1, the second uses webapp.root2, and so on.

Also note whether the server's firewall allows external access to the ports you want to configure.

This article is distributed by blogs and other operating tool platforms OpenWrite Release

Topics: Java Apache Tomcat xml JDK