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

Summary of problems encountered in the implementation of Vue plug-ins

Table of contents Scene Introduction Plugin Imple...

How to create a MySQL database (de1) using commands

1. Connect to MYSQL Format: mysql -h host address...

Zabbix monitoring docker application configuration

The application of containers is becoming more an...

js to achieve simple accordion effect

This article shares the specific code of js to ac...

How to set mysql to case insensitive

mysql set to case insensitive Windows Go to the d...

Detailed explanation of CSS style cascading rules

CSS style rule syntax style is the basic unit of ...

MySQL calculates the number of days, months, and years between two dates

The MySQL built-in date function TIMESTAMPDIFF ca...

Detailed introduction to deploying k8s cluster on centos7 system

Table of contents 1 Version and planning 1.1 Vers...

Upgrading Windows Server 2008R2 File Server to Windows Server 2016

The user organization has two Windows Server 2008...

Detailed explanation of the solution to forget the password in MySQL 5.7

ENV: [root@centos7 ~]# uname -r 3.10.0-514.el7.x8...

How to use lodop print control in Vue to achieve browser compatible printing

Preface This control will have a watermark at the...

js regular expression lookahead and lookbehind and non-capturing grouping

Table of contents Combining lookahead and lookbeh...