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

MySQL 5.7.18 free installation version window configuration method

This is my first blog. It’s about when I started ...

Detailed steps to install JDK and Tomcat in Linux environment

Table of contents 1. Install JDK Manual Installat...

How to configure CDN scheduling using Nginx_geo module

Introducing the Geo module of Nginx The geo direc...

How InnoDB cleverly implements transaction isolation levels

Preface In the previous article Detailed Explanat...

Html+css to achieve pure text and buttons with icons

This article summarizes the implementation method...

JavaScript to display hidden form text

This article shares the specific code of JavaScri...

Basic knowledge of MySQL database

Table of contents 1. Understanding Databases 1.1 ...

JavaScript Shorthand Tips

Table of contents 1. Merge arrays 2. Merge arrays...

Problems installing TensorRT in docker container

Uninstall the installed version on Ubuntu: sudo a...

Docker batch start and close all containers

In Docker Start all container commands docker sta...

VUE render function usage and detailed explanation

Table of contents Preface The role of render Rend...

HTML elements (tags) and their usage

a : Indicates the starting or destination positio...