美文网首页
Tomcat源码魔改maven项目进行debug

Tomcat源码魔改maven项目进行debug

作者: Wannay | 来源:发表于2021-05-20 03:44 被阅读0次

    1、下载源码(Tomcat-9.0.46)

    源码地址如下

    https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-9/v9.0.46/src/apache-tomcat-9.0.46-src.zip

    2、改造为maven工程

    image.png
    <!-- pom.xml -->
    <?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>tomcat9</artifactId>
        <name>tomcat-9.0.46</name>
        <version>9.0.46</version>
        <build>
            <finalName>tomcat-9.0.46</finalName>
            <sourceDirectory>java</sourceDirectory>
            <!--<testSourceDirectory>test</testSourceDirectory>  test 下的有些文件报错,因此将test文件夹去掉了-->
            <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.6.0</version>
                    <configuration>
                        <encoding>UTF-8</encoding>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>3.0.2</version>
                </plugin>
            </plugins>
        </build>
         <dependencies>
            <dependency>
                <groupId>org.apache.ant</groupId>
                <artifactId>ant</artifactId>
                <version>1.9.5</version>
            </dependency>
             <!-- https://mvnrepository.com/artifact/biz.aQute.bnd/annotation -->
             <!-- https://mvnrepository.com/artifact/biz.aQute.bnd/biz.aQute.bndlib -->
             <dependency>
                 <groupId>biz.aQute.bnd</groupId>
                 <artifactId>biz.aQute.bndlib</artifactId>
                 <version>5.2.0</version>
                 <scope>provided</scope>
             </dependency>
    
             <!-- https://mvnrepository.com/artifact/org.apache.jasper/org.apache.jasper -->
             <!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-jasper -->
             <dependency>
                 <groupId>org.apache.tomcat</groupId>
                 <artifactId>tomcat-jasper</artifactId>
                 <version>9.0.44</version>
             </dependency>
             <dependency>
                <groupId>org.apache.ant</groupId>
                <artifactId>ant-apache-log4j</artifactId>
                <version>1.9.5</version>
            </dependency>
            <dependency>
                <groupId>org.apache.ant</groupId>
                <artifactId>ant-commons-logging</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.6.1</version>
            </dependency>
        </dependencies>
    </project>
    

    3、导入idea

    java/org/apache/jasper/compiler/JDTCompiler.java文件中的CompilerOptions.VERSION_15全部替换为CompilerOptions.VERSION_1_8,不然会报错,15版本的Tomcat代码貌似还没写,并将设置项目结构中的JDK版本设为1.8

    image.png image.png

    4、创建启动类

    image.png

    5、添加vm-options避免乱码

    image.png
    -Duser.language=en
    -Duser.region=US
    -Dfile.encoding=UTF-8
    -Dsun.jnu.encoding=UTF-8
    

    5.启动项目

    使用浏览器打开


    image.png

    编译成功

    相关文章

      网友评论

          本文标题:Tomcat源码魔改maven项目进行debug

          本文链接:https://www.haomeiwen.com/subject/bgxvjltx.html