idea 编译运行 tomcat 10.1.28 源码
1. 所需资源
maven
idea (支持 JDK 22)
2. Idea 导入项目
10.1.28.tar.gz
解压到指定文件夹 如 ~\tomcat-source\tomcat-10.1.28
这里等待一段时间,生成 ~\tomcat-source\tomcat-10.1.28\.idea
文件夹
3. 替换Idea生成的临时配置文件
拷贝并覆盖 \tomcat-source\tomcat-10.1.28\res\ide-support\idea
所有文件到 ~\tomcat-source\tomcat-10.1.28\.idea
4. 确认idea 项目配置
- 已安装 ant 插件
- 当前 Project -> SDK 为 JDK 22
- 当前 Project -> Language level 为 22
- 当前 Project Structure ->
apache-tomcat-10.1.28
Language level 为 22 - File -> Settings -> Build, Execution, Deployment -> Compiler-> Java Compiler ->
apache-tomcat-10.1.28
Target bytecode version 为 22 - File -> Settings -> Build, Execution, Deployment -> Build Tools -> Maven -> Runner -> JRE ->
zulu 22
注意以上设置需为 JDK 22 版本, JDK21, 17 编译会有很多错误 (引入了22的一些特性)
5. 编译
- ant 编译
打开 ant 工具栏View -> Tool Windows -> ant
如果 ant 工具栏没有项目,则 点击+
手动导入当前项目下的build.xml
运行 ant 工具栏下的clean
,deploy
当前 Project 项目下会生成一个文件夹 output
- maven 编译
当前项目下 新建一个pom.xml
文件
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.boostarea</groupId>
<artifactId>apache-tomcat-10.1.28</artifactId>
<name>apache-tomcat-10.1.28</name>
<version>10.1.28</version>
<build>
<finalName>apache-tomcat-10.1.28</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>3.13.0</version>
<configuration>
<encoding>UTF-8</encoding>
<source>22</source>
<target>22</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.10.14</version>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-apache-log4j</artifactId>
<version>1.10.14</version>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-commons-logging</artifactId>
<version>1.10.14</version>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.6.3</version>
</dependency>
<dependency>
<groupId>jakarta.xml.rpc</groupId>
<artifactId>jakarta.xml.rpc-api</artifactId>
<version>1.1.4</version>
</dependency>
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>ecj</artifactId>
<version>3.38.0</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>jakartaee-migration</artifactId>
<version>1.0.7</version>
</dependency>
<dependency>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bndlib</artifactId>
<version>7.0.0</version>
</dependency>
</dependencies>
</project>
执行 maven clean compile
,当前目录下生成 target
文件夹
maven pom.xml 文件导入目的为了后面可以debug tomcat
6. 配置debug/run当前已编译的 tomcat
新建一个应用配置
Name: tomcat
Build an run: java 22
module: apache-tomcat-10.1.28 (下拉选)
main class: org.apache.catalina.startup.Bootstrap
Working directory: D:\GitHub\tomcat-source\tomcat-10.1.28\output\build
如下图
7. debug 验证
设置tomcat 断点
基于上面应用配置 启动 debug
访问 http://localhost:8080
访问 http://localhost:8080/examples/