1. 首先下载源码和Tomcat
下载source源码,zip包
2. 编辑pom文件
解压后 在根目录 新建一个
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>com.apache</groupId>
<artifactId>tomcatcode</artifactId>
<version>1.0-SNAPSHOT</version>
<!-- 远程仓库 -->
<repositories>
<repository>
<id>aliyun</id>
<name>aliyun Repository</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>ibiblio</id>
<name>ibiblio Repository</name>
<url>http://mirrors.ibiblio.org/pub/mirrors/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<build>
<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.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>
<!-- junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
3. IDEA 打开 tomcat
4. 设置 Sources 目录 (否则启动无法找到Java主文件)
5. 修改ContextConfig.java
文件
路径 org.apache.catalina.startup.ContextConfig
configureStart 方法里 添加
// 解决启动为空的问题
context.addServletContainerInitializer(new JasperInitializer(), null);
否则便是这样的结果
千辛万苦把Tomcat配置的启动起来了,却发现默认的页面无法打开:
经过重重排查,原因竟然是jsp的编译器没有初始化,我们只需要在apache-tomcat-8.5.76-src\java\org\apache\catalina\startup\ContextConfig.java类中只需添加一句代码即可手动初始化
6. 配置IDEA启动项
参数
org.apache.catalina.startup.Bootstrap