Tomcat源码导入
-
进入官网下载源码工程https://tomcat.apache.org/
-
解压压缩包,得到⽬录 apache-tomcat-8.5.50-src
-
进⼊ apache-tomcat-8.5.50-src ⽬录,创建⼀个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>apache-tomcat-8.5.50-src</artifactId> <name>Tomcat8.5</name> <version>8.5</version> <build> <!--指定源⽬录--> <finalName>Tomcat8.5</finalName> <sourceDirectory>java</sourceDirectory> <resources> <resource> <directory>java</directory> </resource> </resources> <plugins> <!--引⼊编译插件--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <encoding>UTF-8</encoding> <source>11</source> <target>11</target> </configuration> </plugin> </plugins> </build> <!--tomcat 依赖的基础包--> <dependencies> <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> <dependency> <groupId>javax.xml.soap</groupId> <artifactId>javax.xml.soap-api</artifactId> <version>1.4.0</version> </dependency> </dependencies> </project>
-
在 apache-tomcat-8.5.50-src ⽬录中创建 source ⽂件夹
-
将 conf、webapps ⽬录移动到刚刚创建的 source ⽂件夹中
-
将源码⼯程导⼊到 IDEA 中
-
给 tomcat 的源码程序启动类 Bootstrap 配置 VM 参数,指向之前创建的source目录
-Dcatalina.home=D:/objects/apache-tomcat-8.5.50-src/source -Dcatalina.base=D:/objects/apache-tomcat-8.5.50-src/source -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=D:/objects/apache-tomcat-8.5.50-src/source/conf/logging.properties
- 找到Bootstrap的main方法启动运行,并访问http://localhost:8080/
-
找到ContextConfig的configureStart(777行),在
webConfig();
之下添加如下代码context.addServletContainerInitializer(new JasperInitializer(),null);
- 再次运行Bootstrap的main方法,并访问http://localhost:8080,成功访问