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

Detailed explanation of 7 SSH command usages in Linux that you don’t know

A system administrator may manage multiple server...

Detailed explanation of CSS background and border tag examples

1. CSS background tag 1. Set the background color...

VMware12.0 installation Ubuntu14.04 LTS tutorial

I have installed various images under virtual mac...

How to use TypeScript in Vue

introduction In recent years, the call for TypeSc...

In-depth reading and practice records of conditional types in TypeScript

Table of contents Using conditional types in gene...

Let's take a look at some powerful operators in JavaScript

Table of contents Preface 1. Null coalescing oper...

How to use ssh tunnel to connect to mysql server

Preface In some cases, we only know the intranet ...

JavaScript realizes the queue structure process

Table of contents 1. Understanding Queues 2. Enca...

How to use Docker to package and deploy images locally

First time using docker to package and deploy ima...

MySQL batch adding and storing method examples

When logging in to the stress test, many differen...

MySQL encryption and decryption examples

MySQL encryption and decryption examples Data enc...

Solution to the problem of English letters not wrapping in Firefox

The layout of text has some formatting requiremen...

JavaScript canvas Tetris game

Tetris is a very classic little game, and I also ...