Tomcat directory structure and deployment method

The article mainly contains the following content:

  • Tomcat software directory structure and deployment directory structure
  • 3 ways to deploy projects in Tomcat

1 Tomcat directory structure

1.1 Tomcat software directory structure

Insert picture description here

1.2 Java dynamic project directory

Static projects and dynamic projects can be deployed under the Tomcat webapps directory. The Java dynamic project directory may contain the following parts:

-- 根目录
	-- WEB-INF目录
		-- web.xml:web项目的核心配置文件
		-- classes目录:放置字节码文件的目录
		-- lib目录:放置依赖的jar包
  1. IDEA will create a separate configuration file for each tomcat deployed project
    • View the log of the console: Using CATALINA_BASE
  2. Workspace project and web project deployed by tomcat
    • What tomcat really accesses is the "web project deployed by tomcat", and the "web project deployed by tomcat" corresponds to all the resources in the web directory of the "workspace project".
    • The resources in the WEB-INF directory cannot be directly accessed by the browser. The jar package for additional calls should be placed in the WEB-INF directory.

2 The way Tomcat deploys the project

Suppose there is a hello project, and there is hello.html in the project.

2.1 Put the project directly into the webapps directory

The name of the project directory, that is, the access path --> virtual directory. For example, http://localhost:8080/hello/hello.html, you can access the project file.

  • Simplified deployment-package the project into a war package and put it in the webapps directory.
    • When Tomcat starts, put the war package and the project will be automatically decompressed; when the war package is deleted, the project will also be deleted synchronously.

2.1 Configure conf/Server.xml

Configure under the host tag of Server.html

<Context docBase="/home/lzp/hello" path="/hi"/>
  • docBase: project storage path
  • path: virtual access path, browser access http://localhost:8080/hi/hello.html.

2.3 Create an xml file of any name in the conf/Catalina/localhost/ directory

There are two disadvantages to using Server.xml configuration: (1) Server.xml is a global configuration file, and the modification is not safe enough; (2) Hot deployment is not supported, and the change requires restarting Tomcat. The third method can perfectly solve these two problems and is the recommended deployment method.

Assuming that the aaa.xml file is created, the content of the file is

<Context docBase="/home/lzp/hello" />

The virtual directory is the xml file name, and you need to visit http://localhost:8080/aaa/hello.html at this time.

3 View the error log

For back-end logs, you can view the catelina.out file in the log directory.

more catelinna.out 从头查看文件
tail catelina.out -f 动态监听最新

Guess you like

Origin blog.csdn.net/LIZHONGPING00/article/details/112424555