1. 访问tomcat官网
https://tomcat.apache.org/download-80.cgi 根据自己的系统选择源码下载
2 解压
3.解压后,在根目录新建 catalina-home 文件夹和一个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>org.apache.tomcat</groupId>
<artifactId>apache-tomcat-8.5.61-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>
4 .将外部的 webapps 和 conf 两个文件夹挪到这个文件夹下面,再新建 lib logs temp work 几个空文件夹
5.打开idea 导入项目,等待编译
6. JmxRemoteLifecycleListener 可能会报错,导入包
7.编译完成后,再编辑启动类
-Dcatalina.home=E:\spring\apache-tomcat-8.5.61-src\catalina-home
-Dcatalina.base=E:\spring\apache-tomcat-8.5.61-src\catalina-home
-Djava.endorsed.dirsE:\spring\apache-tomcat-8.5.61-src\catalina-home\endorsed
-Djava.io.tmpdirE:\spring\apache-tomcat-8.5.61-src\catalina-home\temp
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Djava.util.logging.config.fileE:\spring\apache-tomcat-8.5.61-src\catalina-home\conf\logging.properties
路径对应换成自己的
7.在org.apache.catalina.startup.ContextConfig类中手动将JSP解析器初始化
context.addServletContainerInitializer(new JasperInitializer(), null);