欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

idea 编译tomcat8源码

程序员文章站 2022-07-14 10:47:24
...

下载tomcat8源码

http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.38/src/apache-tomcat-8.5.38-src.zip

项目结构

将下载下来的源码压缩包解压,然后在解压后的目录中新建pom.xml文件,
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 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>org.apache.tomcat</groupId>
    <artifactId>Tomcat8.0</artifactId>
    <name>Tomcat8.0</name>
    <version>8.0</version>

    <build>
        <finalName>Tomcat8.0</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>2.3</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>
        </dependency>
        <dependency>
            <groupId>ant</groupId>
            <artifactId>ant</artifactId>
            <version>1.7.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.5.1</version>
        </dependency>

    </dependencies>
</project>

构建项目

1.使用IDEA 以maven的项目导入

2.构建好项目后配置启动参数
![image](idea 编译tomcat8源码

注意是自己项目所在目录

Main class设置为org.apache.catalina.startup.Bootstrap

添加VM options  

-Dcatalina.home=D:\code\java_learn\apache-tomcat-8.5.38-src
-Dcatalina.base=D:\code\java_learn\apache-tomcat-8.5.38-src
-Djava.endorsed.dirs=D:\code\java_learn\apache-tomcat-8.5.38-src/endorsed
-Djava.io.tmpdir=D:\code\java_learn\apache-tomcat-8.5.38-src/temp
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Djava.util.logging.config.file=D:\code\java_learn\apache-tomcat-8.5.38-src/conf/logging.properties

util.TestCookieFilter会报错,注释代码即可

启动项目

1.直接启动org.apache.catalina.startup.Bootstrap的时候没有加载org.apache.jasper.servlet.JasperInitializer,从而无法编译JSP。在tomcat的源码org.apache.catalina.startup.ContextConfig类中手动将JSP解析器初始化。

context.addServletContainerInitializer(new JasperInitializer(), null);

idea 编译tomcat8源码

2.修改完后,点击运行或者调试按钮后,正常运行。
idea 编译tomcat8源码

访问浏览器http://localhost:8080/
idea 编译tomcat8源码