How to run tomcat source code in maven mode

How to run tomcat source code in maven mode

Preface

Recently, I was analyzing the startup process of Tomcat. Although we can view the source code of Tomcat in idea, we cannot make some code comments on it, which is very inconvenient. So we can still run a copy of the source code locally, which is very helpful for us to analyze the source code.

1. Download the tomcat source code and select tomcat-8.5.55 version

Go to the tomcat official website, click the corresponding version in the left menu bar Download, and download the source code

2. Create a project in idea

1. Create a blank project in idea named tomcat_study

2. Open the project source directory and unzip the tomcat source code into it

3. Create a folder

Create a home directory under the tomcat source code folder, cut the conf directory and webapps directory in the source code into it (other newly created directories such as logs, etc.), and also create a new maven pom.xml file.

4. Contents of pom.xml file

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 
 <modelVersion>4.0.0</modelVersion>
 <groupId>org.apache.tomcat</groupId>
 <artifactId>Tomcat8.5.55</artifactId>
 <name>Tomcat8.5.55</name>
 <version>8.5.55</version>
 
 <dependencies>
  <dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>4.12</version>
   <scope>test</scope>
  </dependency>
 
  <dependency>
   <groupId>org.easymock</groupId>
   <artifactId>easymock</artifactId>
   <version>3.4</version>
  </dependency>
 
  <dependency>
   <groupId>org.apache.ant</groupId>
   <artifactId>ant</artifactId>
   <version>1.9.5</version>
  </dependency>
 
  <dependency>
   <groupId>javax.xml.rpc</groupId>
   <artifactId>javax.xml.rpc-api</artifactId>
   <version>1.1</version>
  </dependency>
 
  <dependency>
   <groupId>wsdl4j</groupId>
   <artifactId>wsdl4j</artifactId>
   <version>1.6.2</version>
  </dependency>
 
  <dependency>
   <groupId>org.eclipse.jdt.core.compiler</groupId>
   <artifactId>ecj</artifactId>
   <version>4.5.1</version>
  </dependency>
 </dependencies>
 
 <build>
  <finalName>Tomcat8.5.55</finalName>
  <sourceDirectory>java</sourceDirectory>
  <resources>
   <resource>
    <directory>java</directory>
   </resource>
  </resources>
  <plugins>
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
     <encoding>UTF-8</encoding>
     <source>1.8</source>
     <target>1.8</target>
    </configuration>
   </plugin>
  </plugins>
 </build>
</project>

5. Tomcat startup configuration

5.1 Build the project

After completing the above operations, we reopen the project in idea, directly select the pom.xml file we added, and after downloading all the packages, build the project structure.

5.2 Setting Run/Debug configurations

in

Main class:
org.apache.catalina.startup.Bootstrap
 
Modify VM options according to your own path:
-Dcatalina.home=G:/projects/tomcat_study/apache-tomcat-8.5.55-src/home 
-Dcatalina.base=G:/projects/tomcat_study/apache-tomcat-8.5.55-src/home 
-Djava.endorsed.dirs=G:/projects/tomcat_study/apache-tomcat-8.5.55-src/home/endorsed 
-Djava.io.tmpdir=G:/projects/tomcat_study/apache-tomcat-8.5.55-src/home/temp 
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager 
-Djava.util.logging.config.file=G:/projects/tomcat_study/apache-tomcat-8.5.55-src/home/conf/logging.properties

5.3 Setting up the ContextConfig class

Then open the ContextConfig class (under org.apache.catalina.startup) and add a line of code: context.addServletContainerInitializer(new JasperInitializer(),null);

5.4 Start Tomcat

You can debug and view the initialization and startup process of tomcat and other source code execution. The entry class is the main method of the Bootstrap class.

Summarize

Through the above process, we can run the tomcat source code locally through maven. The editor has successfully run it and annotated the process of calling servlet initialization in tomcat.

This is the end of this article on how to run tomcat source code in maven mode. For more relevant content about running tomcat source code in maven mode, 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:
  • Solve the problem that idea compiles normally using Maven but many jar packages cannot be found when running the project
  • Detailed explanation of two ways to run projects through Maven

<<:  CSS Houdini achieves dynamic wave effect

>>:  Xhtml special characters collection

Recommend

How to expand the disk size of a virtual machine

After Vmvare sets the disk size of the virtual ma...

8 powerful techniques for HTML web page creation

<br />Although there are many web page creat...

User needs lead to marketing-oriented design

<br />For each of our topics, the team will ...

What is Nginx load balancing and how to configure it

What is Load Balancing Load balancing is mainly a...

Using cursor loop to read temporary table in Mysql stored procedure

cursor A cursor is a method used to view or proce...

Solution to the error when calling yum in docker container

When executing yum in dockerfile or in the contai...

How to install babel using npm in vscode

Preface The previous article introduced the insta...

Solution for multiple Docker containers not having the same port number

Background In Docker, four containers are created...

CSS screen size adaptive implementation example

To achieve CSS screen size adaptation, we must fi...

Special commands in MySql database query

First: Installation of MySQL Download the MySQL s...

Vue's new partner TypeScript quick start practice record

Table of contents 1. Build using the official sca...

How to write configuration files and use MyBatis simply

How to write configuration files and use MyBatis ...

Implementation of Docker cross-host network (manual)

1. Introduction to Macvlan Before the emergence o...