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

A complete list of commonly used Linux commands (recommended collection)

Table of contents 1. System Information 2. Shutdo...

Analysis of multi-threaded programming examples under Linux

1 Introduction Thread technology was proposed as ...

Detailed explanation of the this pointing problem in JavaScript

Summarize Global environment ➡️ window Normal fun...

How to install and configure Docker nginx

Download Nginx image in Docker docker pull nginx ...

Troubleshooting MySQL high CPU load issues

High CPU load caused by MySQL This afternoon, I d...

html option disable select select disable option example

Copy code The code is as follows: <select> ...

Summary of MySQL LOAD_FILE() function method

In MySQL, the LOAD_FILE() function reads a file a...

Mini Program to Implement Text Circular Scrolling Animation

This article shares the specific code of the appl...

jQuery achieves fade-in and fade-out effects

Before using jQuery to complete the fade-in and f...

Use Docker to build a Redis master-slave replication cluster

In a cluster with master-slave replication mode, ...

Docker overlay realizes container intercommunication across hosts

Table of contents 1. Docker configuration 2. Crea...

Getting Started Guide to MySQL Sharding

Preface Relational databases are more likely to b...

Introduction to building a DNS server under centos7

Table of contents 1. Project environment: 2: DNS ...

Automatic line breaks in html pre tags

At this time, you can use overflow:auto; (when the...