源码获取
使用git clone
命令获取9.0.x
源码:git clone -b 9.0.x git@github.com:apache/tomcat.git
Idea运行
添加pom.xml
tomcat9项目是使用ant编译的,需要先将其使用maven管理。
新建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>tomcat</artifactId>
<name>tomcat</name>
<version>9.0.19</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.10.5</version>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.6.3</version>
</dependency>
<dependency>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bndlib</artifactId>
<version>5.2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jaxrpc_1.1_spec</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>ecj</artifactId>
<version>3.17.0</version>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>4.0.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
点击pom.xml文件,右键Add as Maven Project
。点击右侧maven工具箱,下载依赖并同步项目。
设置目录
将java设置为Sources Root
目录,test设置为Test Sources Root
目录:
lib目录
官网下载一个可运行的tomcat包,将其中的lib包复制到项目中:
移除不用的文件夹
仅保留webapps下面的ROOT文件夹
启动项目
找到Bootstrap
类,点击运行:
报错:
C:\Users\YuYang\Documents\code\opensource\tomcat\java\org\apache\jasper\compiler\JDTCompiler.java:305:76
java: 找不到符号
符号: 变量 VERSION_12
位置: 类 org.eclipse.jdt.internal.compiler.impl.CompilerOptions
将报错找不到的常量注释掉后再次运行: