将下载下来的源码压缩包解压,然后在解压后的目录中新建catalina-home目录和pom.xml文件,将跟目录中的conf和webapps文件夹移动到catalina-home目录中,如下
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>
catalina-home目录结构如下,没有的目录结构新建空文件夹
将源码导入到idea工程中运行配置参数
Main class
org.apache.catalina.startup.Bootstrap
Vm启动参数
-Dcatalina.home=F:\tomcat8-src\apache-tomcat-8.0.53-src\catalina-home -Dcatalina.base=F:\tomcat8-src\apache-tomcat-8.0.53-src\catalina-home -Djava.endorsed.dirs=F:\tomcat8-src\apache-tomcat-8.0.53-src\catalina-home/endorsed -Djava.io.tmpdir=F:\tomcat8-src\apache-tomcat-8.0.53-src\catalina-home/temp -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
启动项目报错
F:\tomcat8-src\apache-tomcat-8.0.53-src\test\util\TestCookieFilter.java找不到符号这个类是测试中的类,直接删除即可
java.lang.ClassNotFoundException: websocket.drawboard.DrawboardContextListener只需将/webapps/example 文件夹删除删除即可。
启动成功之后访问127.0.0.1:8080报错
在org.apache.catalina.startup.ContextConfig类中手动将JSP解析器初始化
context.addServletContainerInitializer(new JasperInitializer(), null);
添加到 webConfig(); 后面