目的: 搭建源码阅读环境
1.环境准备
tomcat和jdk匹配关系(Apache Tomcat® - Which Version Do I Want?)
- jdk8
- maven-3.5.4
注意: 如果因为maven版本问题导致编译不成功,尝试换成 maven-3.5.4
2.下载tomcat9源码
https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.55/src/apache-tomcat-9.0.55-src.zip (用迅雷下载很快)
3.修改项目结构
将下载下来的源码压缩包解压,然后在解压后的目录中新建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>Tomcat9.0.55</artifactId>
<name>Tomcat9.0.55</name>
<version>c</version>
<build>
<finalName>Tomcat9.0.55</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.6.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>4.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.10.8</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>
<dependency>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bndlib</artifactId>
<version>5.1.1</version>
</dependency>
<dependency>
<groupId>com.unboundid</groupId>
<artifactId>unboundid-ldapsdk</artifactId>
<version>4.0.13</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
4.构建项目
1)使用IDEA 选中pom.xml,以maven的项目导入
2)构建好项目后配置启动参数
注意是自己项目所在目录
Main class设置为org.apache.catalina.startup.Bootstrap
添加VM options
-Dcatalina.home=F:/Resource/apache-tomcat-9.0.55-src
-Dcatalina.base=F:/Resource/apache-tomcat-9.0.55-src
-Djava.endorsed.dirs=F:/Resource/apache-tomcat-9.0.55-src/endorsed
-Djava.io.tmpdir=F:/Resource/apache-tomcat-9.0.55-src/temp
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Djava.util.logging.config.file=F:/Resource/apache-tomcat-9.0.55-src/conf/logging.properties
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=8011
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Duser.language=en
-Duser.region=US
JDTCompiler关于版本报错部分注释掉
5.启动项目
1)直接启动org.apache.catalina.startup.Bootstrap的时候没有加载org.apache.jasper.servlet.JasperInitializer,从而无法编译JSP。在org.apache.catalina.startup.ContextConfig#configureStart中修改源码将JSP解析器初始化。
//JSP解析器初始化
context.addServletContainerInitializer(new JasperInitializer(), null);
2)修改完后,启动运行。访问浏览器http://localhost:8080/