arthas-boot.jar 热替换

下载 arthas-boot.jar

bash 复制代码
curl -O https://arthas.aliyun.com/arthas-boot.jar

一、现在你还没进 Arthas(很重要)

你刚才只是 lspwd
还没有真正 attach JVM

👉 现在请执行这一条命令:

bash 复制代码
java -jar arthas-boot.jar

二、你接下来一定会看到这个界面(正常)

类似这样 👇

复制代码
Found existing java process, please choose one and hit RETURN.
* [1]:  23145 demo20250304-0.0.1-SNAPSHOT.jar

👉 你要做的事:

  • 看清楚是你这个 jar:

    复制代码
    demo20250304-0.0.1-SNAPSHOT.jar
  • 输入前面的数字,比如:

text 复制代码
1

然后 回车


三、看到这个,说明你成功进 Arthas 了 ✅

复制代码
Welcome to Arthas!

并且命令行前缀会变成:

text 复制代码
[arthas@23145]$

到这一步,你已经成功 attach 正在运行的 JVM

后面所有操作,都是 不重启、直接改内存


四、定位 BookController(第一条 Arthas 命令)

在 Arthas 控制台里,输入👇:

bash 复制代码
sc *BookController*

正常你会看到类似:

复制代码
com.example.demo.controller.BookController

👉 把这个完整包名记住

假设是:

复制代码
com.example.demo.controller.BookController

五、确认类信息(非常重要,不跳)

bash 复制代码
sc -d com.example.demo.controller.BookController

你主要看两点:

  • classLoaderHash
  • location(一般是 BOOT-INF/classes)

只要能正常显示,就可以 redefine


六、现在开始真正热替换(核心一步)

⚠️ 注意:
这条命令里的路径,是 Linux 绝对路径

你的 class 在:

复制代码
/root/1230/BookController.class

👉 在 Arthas 控制台中执行:

bash 复制代码
redefine /root/1230/BookController.class

七、成功标志(你要看到这个)

复制代码
redefine success, size: 1

🎉 恭喜你,此时:

  • ❌ 没有重启 jar
  • ❌ 没有改磁盘 jar
  • ✅ BookController 的新逻辑已在 JVM 内存中生效

八、立刻验证(必须做)

方式一:直接调接口

bash 复制代码
curl http://localhost:8080/你BookController的接口

方式二:看日志(强烈推荐)

如果你在新代码里加了类似:

java 复制代码
log.info("=== arthas hotfix ===");

那你现在一请求接口,就应该能看到。


九、如果 redefine 报错(别慌,对号入座)

❌ 报 VerifyError

👉 你改了方法签名 / 字段 / 注解

❌ 报 Unsupported major.minor

👉 class 编译 JDK 和线上不一致

❌ 提示找不到 class

👉 说明这个 Controller 还没被加载(极少)


十、非常重要的一句话(老工程师经验)

Arthas 热修 = 临时止血
一定要记得:后续正常打包 + 重启发布

否则:

  • JVM 一重启
  • 你的修改就 全部消失

shell 复制代码
[root@VM-12-7-centos 1230]# java -jar arthas-boot.jar
[INFO] JAVA_HOME: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.412.b08-1.el7_9.x86_64/jre
[INFO] arthas-boot version: 4.1.4
[INFO] Found existing java process, please choose one and input the serial number of the process, eg : 1. Then hit ENTER.
* [1]: 20038 demo20250304-0.0.1-SNAPSHOT.jar
1
[INFO] arthas home: /root/.arthas/lib/4.1.4/arthas
[INFO] Try to attach process 20038
Picked up JAVA_TOOL_OPTIONS: 
[INFO] Attach process 20038 success.
[INFO] arthas-client connect 127.0.0.1 3658
  ,---.  ,------. ,--------.,--.  ,--.  ,---.   ,---.                           
 /  O  \ |  .--. ''--.  .--'|  '--'  | /  O  \ '   .-'                          
|  .-.  ||  '--'.'   |  |   |  .--.  ||  .-.  |`.  `-.                          
|  | |  ||  |\  \    |  |   |  |  |  ||  | |  |.-'    |                         
`--' `--'`--' '--'   `--'   `--'  `--'`--' `--'`-----'                          

wiki         https://arthas.aliyun.com/doc                                      
tutorials    https://arthas.aliyun.com/doc/arthas-tutorials.html                
version      4.1.4                                                              
main_class   demo20250304-0.0.1-SNAPSHOT.jar                                    
pid          20038                                                              
start_time   2025-12-31 00:14:37.452                                            
current_time 2025-12-31 00:15:05.480                                            

[arthas@20038]$ redefine /root/1230/BookController.class
redefine success, size: 1, classes:
com.example.demo20250304.controller.BookController
[arthas@20038]$ 
相关推荐
蝎子莱莱爱打怪43 分钟前
OpenClaw 从零配置指南:接入飞书 + 常用命令 + 原理图解
java·后端·ai编程
狼爷2 小时前
Go 没有 override?别硬套继承!用接口+嵌入,写更清爽的“覆盖”逻辑
java·go
小兔崽子去哪了5 小时前
Java 自动化部署
java·后端
ma_king5 小时前
入门 java 和 数据库
java·数据库·后端
后端AI实验室5 小时前
我用Cursor开发了3个月,整理出这套提效4倍的工作流
java·ai
zone77398 小时前
001:简单 RAG 入门
后端·python·面试
F_Quant8 小时前
🚀 Python打包踩坑指南:彻底解决 Nuitka --onefile 配置文件丢失与重启报错问题
python·操作系统
码路飞9 小时前
GPT-5.3 Instant 终于学会好好说话了,顺手对比了下同天发布的 Gemini 3.1 Flash-Lite
java·javascript
允许部分打工人先富起来9 小时前
在node项目中执行python脚本
前端·python·node.js
IVEN_9 小时前
Python OpenCV: RGB三色识别的最佳工程实践
python·opencv