SoFunction
Updated on 2025-03-08

Summary of configuration methods for tomcat virtual path

Generally, we directly refer to the web project under webapps. If we want to deploy a WEB project in other places, we need to set a virtual path in TOMCAT. The order in which Tomcat loads the web is to first load the xml file under $Tomcat_home$\conf\Catalina\localhost (the path of the web project is configured in the file), and then load the web project under webapps.

If we want to deploy the XXX project below d:\project\ (XXX is the project name).

At this time we have two methods:

Method 1: Create a new XML file under the path of $Tomcat_home$\conf\Catalina\localhost, Note: The name of the XML file is the web root path after the project is successfully deployed. If this is defined, then the subsequent access path ishttp://ip:port/test, the file content is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<Context docBase="D:\project\XXX" reloadable="true" debug="0" path="/test"/>
 

In fact, path="/test" is not written here. At this time, path is actually determined by the name of the xml file, so it can be abbreviated as

<Context docBase="D:\project\XXX" reloadable="true" debug="0" />

This sets the virtual path of /test

Method 2: Edit the server file (%tomcathome%\conf\)
We plan to create a virtual directory of myjsp. Just add the following code to the %tomcathome%\conf\ file and add the following code to the <host> tag:

<Context docBase="D:\project\XXX" reloadable="true" debug="0" path="/test"/>

Note that you must write the path at this time, because we have not created a new XML file at this time, so you must specify the web.

The meaning of configuration file attributes:

debug  should be to integrate the tomcat server and development tools when debugging the Java code of a web project, or require some plug-in support for the tool (such as myclipse under Eclipse, etc.). These methods are all carried out locally, that is, your development tools and tomcat are running on the same server. If your development tools and server are no longer on the same machine, you need to implement remote control.

Debug function.

In fact, log4j package is introduced in general Java project development, and debugging information is output during the development process through configuration. If there is no special request, it is recommended to take the time to study it.

At that time, the setting of the reloadable attribute is useful. When reloadable=true, the relevant files will change. Tomcat first stops the web app and frees up the memory, and then reloads the web app. This will save time manually deploying web app projects. Working with development tools can slightly improve productivity.