Tomcat 8.5.82源码阅读,导入IDEA

闲来无事学习一下tomcat源码,导入过程记录如下

  1. 首先官网下载tomcat源码,下载地址:Apache Tomcat® - Apache Tomcat 8 Software Downloads

  2. 将下载的源码解压到本地目录下

  3. 在源码根目录下新建pom文件,内容如下:

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">  
    <modelVersion>4.0.0</modelVersion>  
    <groupId>org.apache</groupId>  
    <artifactId>tomcat</artifactId>  
    <name>apache-tomcat-8.5.82</name>  
    <version>8.5.82</version>  
  
    <build>  
        <finalName>Tomcat-8.5.82</finalName>  
        <sourceDirectory>java</sourceDirectory>  
        <testSourceDirectory>test</testSourceDirectory>  
        <resources>  
            <resource>  
                <directory>java</directory>  
            </resource>  
        </resources>  
        <testResources>  
            <testResource>  
                <directory>test</directory>  
            </testResource>  
        </testResources>  
        <plugins>  
            <plugin>  
                <groupId>org.apache.maven.plugins</groupId>  
                <artifactId>maven-compiler-plugin</artifactId>  
                <version>3.5.1</version>  
                <configuration>  
                    <encoding>UTF-8</encoding>  
                    <source>1.8</source>  
                    <target>1.8</target>  
                </configuration>  
            </plugin>  
        </plugins>  
    </build>  
  
    <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>  
            <scope>test</scope>  
        </dependency>  
  
        <dependency>  
            <groupId>org.apache.ant</groupId>  
            <artifactId>ant</artifactId>  
            <version>1.10.0</version>  
        </dependency>  
        <dependency>  
            <groupId>wsdl4j</groupId>  
            <artifactId>wsdl4j</artifactId>  
            <version>1.6.2</version>  
        </dependency>  
        <dependency>  
            <groupId>javax.xml</groupId>  
            <artifactId>jaxrpc</artifactId>  
            <version>1.1</version>  
        </dependency>  
        <dependency>  
            <groupId>org.eclipse.jdt.core.compiler</groupId>  
            <artifactId>ecj</artifactId>  
            <version>4.6.1</version>  
        </dependency>  
        <!-- https://mvnrepository.com/artifact/org.glassfish/javax.xml.rpc -->  
        <dependency>  
            <groupId>org.glassfish</groupId>  
            <artifactId>javax.xml.rpc</artifactId>  
            <version>3.0.1-b03</version>  
        </dependency>  
  
    </dependencies>  
  
</project>

  1. 在IDEA中导入Tomcat源码项目文件
  2. 添加VM参数
-Dcatalina.home=D:\projects\nothing\apache-tomcat-8.5.82-src
-Dcatalina.base=D:\projects\nothing\apache-tomcat-8.5.82-src
-Djava.endorsed.dirs=D:\projects\nothing\apache-tomcat-8.5.82-src\endorsed
-Djava.io.tmpdir=D:\projects\nothing\apache-tomcat-8.5.82-src\temp
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Djava.util.logging.config.file=D:\projects\nothing\apache-tomcat-8.5.82-src\conf\logging.properties
# 下方配置为解决乱码问题
-Duser.language=en
-Duser.region=en
-Dfile.encoding=UTF-8
-Dsun.jun.encoding=UTF-8

  1. 在ContextConfig类中configureStart方法中添加初始化Servlet容器:
context.addServletContainerInitializer(new JasperInitializer(), null);

  1. 启动Tomcat, 在启动过程中test中部分文件出现报错异常,直接删除报错文件即可;

  2. 在VM中配置防止乱码参数在启动日志中打印如下:

  3. 访问查看Tomcat启动成功

posted @ 2022-09-21 00:25  justKen  阅读(234)  评论(0编辑  收藏  举报