Solution for Tomcat to place configuration files externally

Solution for Tomcat to place configuration files externally

question

When we are developing normally, if we want to deploy the project to Tomcat, the general practice is to package the project into a war package, then throw the war package into the webapps directory of Tomcat, and then start the project.

However, when deploying a project to a production environment, the configuration files of the production environment are generally different from those of the local development environment. In this case, it is more troublesome to deploy the project to production using the method just described. You need to manually delete the original configuration files, or exclude the configuration files when packaging, and then copy the correct configuration files to the resource directory of the project.

So, is there a simpler way?

Workaround

We can put the configuration files in a fixed location on the server, such as /var/config. Then import these configuration files into Tomcat.
The specific steps are as follows:

  • Enter the Tomcat root directory

  • Enter the conf directory and create a folder Catalina
  • Enter the Catalina directory and create a folder called localhost
  • Go to the localhost directory and create the file appContext.xml

Special note: appContext here is the context of your project, you need to change it to your own project context name, for example: taobao.xml

Fill in appContext.xml like this

<Context path ="/appContext" docBase ="/home/tools/apps/appContext.war"
        debug ="0" privileged ="true" reloadable ="true" >
        <Parameter name="" value="/home/tools/config" override="false"/>
</Context>

path: fill in the context of your project docBase: fill in the war package path value: fill in the project configuration file path

Go back to the Tomcat directory, then enter the bin directory and modify the setenv.sh file

CLASSPATH=$CLASSPATH:/home/tools/config

If this file does not exist, create it and set executable permissions.

  • The configuration is basically complete, then put the configuration file in the corresponding directory, put the war package in the corresponding directory, and start Tomcat.

My configuration file corresponds to the directory /home/tools/config, and the war package directory is /home/tools/apps/appContext.war. You can modify these two paths according to your needs.

Finally, let me share a little knowledge, Tomcat sets the memory size

In the bin directory of Tomcat, open the catalina.sh file and add the following line to the first line of the official code: JAVA_OPTS="-server -Xms128m -Xmx256m -XX:PermSize=64M -XX:MaxPermSize=128m"
The specific memory size needs to be set according to your needs

Summarize

This is the end of this article about placing Tomcat configuration files externally. For more information about placing Tomcat configuration files externally, 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:
  • How to configure the maxPostSize value of built-in Tomcat in Spring Boot
  • Detailed steps for configuring springboot using external tomcat in idea
  • Three ways to configure JNDI data source in Tomcat
  • A brief discussion on the correct posture of Tomcat memory configuration
  • Detailed explanation of optimized configuration of Tomcat user management

<<:  How to create your first React page

>>:  Web Standard Application: Redesign of Tencent QQ Home Page

Recommend

Analysis of the reasons why MySQL field definitions should not use null

Why is NULL so often used? (1) Java's null Nu...

mysql having usage analysis

Usage of having The having clause allows us to fi...

Zabbix's psk encryption combined with zabbix_get value

Since Zabbix version 3.0, it has supported encryp...

How to connect Navicat to the docker database on the server

Start the mysql container in docekr Use command: ...

Tools to convert static websites into RSS

<br /> This article is translated from allwe...

Using Vue3 (Part 1) Creating a Vue CLI Project

Table of contents 1. Official Documentation 2. Cr...

Summary of Mysql update multi-table joint update method

Next, I will create two tables and execute a seri...

Detailed explanation of this reference in React

Table of contents cause: go through: 1. Construct...

JavaScript functional programming basics

Table of contents 1. Introduction 2. What is func...

Detailed explanation of :key in VUE v-for

When key is not added to the v-for tag. <!DOCT...

JavaScript implements class lottery applet

This article shares the specific code of JavaScri...

Detailed explanation of three ways to set borders in HTML

Three ways to set borders in HTML border-width: 1...

How to get the height of MySQL innodb B+tree

Preface The reason why MySQL's innodb engine ...

Detailed explanation of nginx shared memory mechanism

Nginx's shared memory is one of the main reas...