idea 编译断点运行 tomcat 10.1.28 源码

idea 编译运行 tomcat 10.1.28 源码

1. 所需资源

tomcat 10.1.28
zulu JDK 22

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/

相关推荐
budingxiaomoli1 小时前
Spring统一功能处理
java·后端·spring
Flynn Liang2 小时前
可观测性与成本治理:一次对话的 17 个观测点
java·langchain·可观测性·micrometer·langchain4j·token 成本·llm 监控
金銀銅鐵3 小时前
带您看懂字节码指令(三):同一行加法,为什么有四种指令
java·jvm
文丑颜不良啊7 小时前
LeetCode2821~2840题目解析
java·leetcode
apcipot_rain7 小时前
C++转Java日记(10)
java·开发语言
简 洁 冬冬8 小时前
泛型方法写法全面辨析:从「能编译」到「能跑」到「能用」
java·泛型
LGL6030A8 小时前
Java学习历程31——初识Spring Boot
java·spring boot·学习
Lansonli10 小时前
大数据Spark(八十八):Spark任务资源之Standalone集群测试
java·服务器·spark
budingxiaomoli10 小时前
Spring AOP
java·spring·java-ee
特立独行的猫A10 小时前
Ionic + 仓颉语言的 cj-tauri 开发框架实战:开发精美移动端 APP
java·后端·python