Methods and steps for deploying multiple war packages in Tomcat

Methods and steps for deploying multiple war packages in Tomcat

1 Background

JDK1.8-u181 and Tomcat8.5.53 were installed.

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

Two war packages need to be released, MES and ERP.

2 Install Tomcat

I used the .exe file to install it, and after installation I did not configure tomvat_home (because I don't know if it needs to be configured)

3 Copy folder

3.1 Installation DirectoryconfCatalina

Catalina is a folder. Copy Catalina into two folders, one named CatalinaMES and the other named CatalinaERP. Put them both in the installation directory\conf directory.

3.2 Installation Directory webapps

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

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

The war package of the ERP project is placed in the installation directory\webappsERP

4 Modify the configuration file

Modify the content in 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>

Among them, a <service> node represents a service, that is, a deployed project.

The name attribute of the <service> node is changed to the name of the corresponding Catalina folder. The name attribute of the <Engine> node is also changed to the name of the corresponding Catalina folder.

The port attribute of the <Connector> node is the port number of the project. Just be careful not to conflict with it.

The appBase property of the <Host> node is changed to the corresponding webapps folder.

The path attribute of the <Context> node is the address used for access, that is, the access address of the project is服務器ip:項目端口號/path屬性的值. According to the current configuration, the local access address of my MES project is 127.0.0.1:8085/mes-manager-web . The docBase attribute of the <Context> node is the local path of the project war package. Just change it to the absolute path of the war package on the local machine.

5 Modify startup.bat and shutdown.bat

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

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

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

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

6 Double-click startup.bat to run tomcat

Note that a DOS window will be opened at this time, which will print the project startup information like the IDEA console. When the project is successfully started, do not close this DOS window, keep it open, if you turn off Tomcat, it will stop running.

7 Notes

If multiple projects use the Spring framework, an error may occur when configuring a tomcat with multiple ports and multiple applications.

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

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

Ensure that the <param-name> of each project's web.xml is different from the <param-value> corresponding to webAppRootKey. For example, the first one uses webapp.root1, the second one uses webapp.root2, and so on.

In addition, please pay attention to whether the server's firewall allows external access to the port you want to configure.

This is the end of this article about the steps to deploy multiple war packages with Tomcat. For more information about deploying multiple war packages with Tomcat, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Idea packaged into war package deployed to tomcat and access path issues (illustration and text)
  • Three ways to deploy web applications to the Tomcat root directory
  • Solution to the problem that SpringBoot application cannot be started when deployed to Tomcat
  • Summary of 4 methods of deploying web applications with tomcat (recommended)
  • Detailed steps to deploy tomcat and java applications in docker
  • About the problem that the tomcat deployed application cannot access the front-end page

<<:  Implementation of vue3.0+vant3.0 rapid project construction

>>:  Detailed Analysis of or, in, union and Index Optimization in MySQL

Recommend

Docker file storage path, modify port mapping operation mode

How to get the container startup command The cont...

Nodejs error handling process record

This article takes the connection error ECONNREFU...

Detailed explanation of how to solve the problem of too long content in CSS

When we write CSS, we sometimes forget about the ...

Detailed explanation of JSONObject usage

JSONObject is just a data structure, which can be...

English: A link tag will automatically complete href in IE

English: A link tag will automatically complete h...

How to completely uninstall Docker Toolbox

Docker Toolbox is a solution for installing Docke...

JavaScript canvas to achieve scratch lottery example

This article shares the specific code of JavaScri...

MySQL table auto-increment id overflow fault review solution

Problem: The overflow of the auto-increment ID in...

Data URI and MHTML complete solution for all browsers

Data URI Data URI is a scheme defined by RFC 2397...

How to modify the root password of mysql in docker

The first step is to create a mysql container doc...

User Experience Summary

Nowadays, whether you are working on software or w...

MySQL multi-table query detailed explanation

Eating well and getting enough rest sounds simple...

Analysis of CocosCreator's new resource management system

Table of contents 1. Resources and Construction 1...