1 background

I installed jdk1.8-u181 and Tomcat8.5.53.

After installation, JAVA_HOME and Path are configured in the environment variables. With JRE, not with JDK.

There are two WAR packages to release, MES and ERP.

2 install Tomcat

I installed with.exe file without tomvat_HOME (because I don’t know if IT needs to be configured)

3 Copying folders

3.1 Installation Directory \conf\Catalina

Catalina is a folder. Make two copies of Catalina, one named CatalinaMES and the other CatalinaERP, under the installation directory \conf

3.2 Installation directory \webapps

Webapps is also a folder. Make two copies, one named webappsMES and the other named webappsERP, and put them in the installation directory

The WAR package for the MES project is placed in the installation directory \webappsMES

The WAR package for the ERP project is placed under the installation directory \webappsERP

4 Modify the configuration file

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

<? The 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> <! <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> <! <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>Copy the code

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

The name attribute 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 attribute of the node is the port number of the project.

The appBase property of the node is changed to the corresponding WebApps folder.

The path attribute of a node is the address at which it is accessed, i.e. the project’s access address is the server IP: the project port number/the value of the path attribute. As currently configured, the native access address for my MES project is 127.0.0.1:8085/mes-manager-web. The docBase attribute of the node is the local path of the project WAR package.

5 Modify startup.bat and shutdown.bat

Edit the installation directory \bin\startup.bat and add:

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

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

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

6 Double-click startup.bat to run Tomcat

Note that a DOS window will open, which will print the startup information of the project like the console of IDEA. When the project is successfully started, do not close the DOS window. Leave it open

7 Precautions

If multiple projects use the Spring framework, errors may be reported when configuring to a Tomcat multi-port multi-application.

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>Copy the code

Ensure that the web.xml for each project is different from the corresponding webAppRootKey. For example, the first one uses webapp.root1, the second one webapp.root2, etc.

Also, be aware that your server’s firewall allows external access to the port you want to configure.

This article is published by OpenWrite, a blogging tool platform