SoFunction
Updated on 2025-03-08

Tomcat how to modify the default access project name and project publishing path

Tomcat modify the default access project name and project publishing path

1. Modify the project release path

Tomcat's default publishing path istomcat/webapps/Directory, but there are some default projects in this directory, which will be loaded together when tomcat is started.

If you do not want to delete these items, you can modify the path published by tomcat to another place.

turn uptomcat/conf/File, modify the line insideappBaseJust use other paths.

<Host name="localhost"  appBase="/root/webfile/webapps" unpackWARs="true" autoDeploy="true">

in:

  • name is the virtual host name, corresponding to directory /conf /Catalina /localhost
  • unpackWARs is whether to automatically decompress the war file. If set to true, it means that the war file is expanded first and then run. If false, run the war file directly
  • autoDeploy, default is true, means that if a new WEB application is placed in the appBase and Tomcat is running, the application will be loaded automatically.

Especially:

You can use either relative or absolute paths here.

Relative path defaulttomcatThe directory is the root directory

2. Modify the default access project

The simplest thing is to modify the project name directly toROOT, puttomcat/webapps/Just a directory.

If you don't want to modify it. Then in step 1

<Host name="localhost"  appBase="/root/webfile/webapps" unpackWARs="true" autoDeploy="true">

Just add the following sentence, which

&lt;!-- Set the default project name --&gt;
&lt;Context path="" docBase="/root/webfile/web" reloadable="true"/&gt; 
  • pathRepresents the path when accessing with the browser, such as http://localhost:8080/web to access path="/web"
  • docBaseFor the path of your project, you can also use either relative or absolute paths. After setting it, the project will be automatically mapped to ROOT
  • reloadable, If this property is set to true, the tomcat server will monitor changes in class files in the WEB-INF/classes and WEB-INF/lib directories under running state. If a class file is monitored, the server will automatically reload the web application.

Tomcat configuration access project without adding project name

When you type a project into a war package and put it in the tomcat webapps directory, you can only access it through the project name. So how do you omit the project name to access it directly?

Method 1 (simple and fast)

The method is very simple. First, delete all folders in the webapps directory, put the packaged war into webapps, and name it. Then you can access it directly after restarting tomcat, without adding the project name.

Method 2

Open the conf/file in the tomcat installation directory, and add the Context node docBase="Project Absolute Path" under the `HOST` node

&lt;Context path="/" docBase="E:\tomcat\apache-tomcat-9.0.19\webapps\project name" debug="0" reloadable="true" /&gt;

It means that this project has been put into the webapps directory and is decompressed.

&lt;Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true" xmlNamespaceAware="false" xmlValidation="false"&gt;
     &lt;!-- pathLeave blank to indicate that the name of the domain name does not need to be included in the project. --&gt;
     &lt;Context path="" docBase="webaaa" reloadable="false" /&gt;
&lt;/Host&gt;
  • docBase: The path representing the project's location (absolute path and relative path are both OK)
  • path: Represents the project name when visiting

Notice:

The project will be loaded twice, and can be accessed with the project name or without it, so it will cause the timed task to be executed twice; it is not recommended to use

Change the project to ROOT, do you need to delete <Context path="" docBase="webaaa" reloadable="false" />, there is no verification. If it is not deleted, will the timing task be executed twice? There is no verification

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.