tomcat8源码分析00-源码启动
git clone https://github.com/apache/tomcat.git tomcat8
# 克隆源码并切换到8.5.x版本
git checkout 8.5.x
2.项目根目录新建并配置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>cn.xxx</groupId>
<artifactId>Tomcat8.5.x</artifactId>
<name>Tomcat8</name>
<version>8.5.x</version>
<build>
<finalName>Tomcat8</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>2.3</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.10.1</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>
<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.5.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bndlib</artifactId>
<version>5.2.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
如果idea没有识别到maven项目需要自己手动link一下。右键pom.xml找到Add as Maven Project
点击maven的clean可能提示找不到jdk,按着提示配置jdk
3.idea设置启动配置
Main class:
org.apache.catalina.startup.Bootstrap
VM options:
-Dcatalina.home=/Users/username/Desktop/java/tomcat8 -Dcatalina.base=/Users/username/Desktop/java/tomcat8 -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=/Users/username/Desktop/java/tomcat8/conf/logging.properties -Dfile.encoding=UTF8 -Duser.language=en -Duser.region=US
4.启动后无法编译jsp文件报错500 找到ContextConfig类,找到代码webConfig();在下一行增加
context.addServletContainerInitializer(new JasperInitializer(), null);