很多时候java代码不能在线调试或者关键地方没有打log导致无法查bug,遇到这种情况可以借助arthas工具来实现java代码热更新且不用重启服务。具体热更新步骤如下
官方文档:https://arthas.aliyun.com/doc/
下载地址:https://github.com/alibaba/arthas/releases
把arthas工具放到要调整的java程序服务器上。
java -jar arthas-boot.jar
[INFO] arthas-boot version: 3.5.3
[INFO] Found existing java process, please choose one and input the serial number of the process, eg : 1. Then hit ENTER.
* [1]: 1 /test.jar
1
[INFO] Start download arthas from remote server: https://arthas.aliyun.com/download/3.6.7?mirror=aliyun
[INFO] File size: 12.92 MB, downloaded size: 9.29 MB, downloading ...
[INFO] Download arthas success.
[INFO] arthas home: /root/.arthas/lib/3.6.7/arthas
[INFO] Try to attach process 1
[INFO] Attach process 1 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 3.6.7
main_class
pid 1
time
注意会打印出 [1]: 1 /test.jar
,选择自己要操作的java实例。
建议提前准备好需要热更新的java class文件,虽然arthas也能编译源码,但并不是编译源码都能通过。
注意:自己提前编译的环境要跟生产环境保持一致,避免不必要的错误。
代码热更新必须提前知道类的classLoader是哪个,后续命令会用到。命令:sc -d *java类名称
sc -d *Test
439f5b3d
记住这个hash,后续命令用到
[arthas@1]$ redefine -c 439f5b3d /Test.class
redefine success, size: 1, classes:
到此更新完毕
市面上有很多HTTP模拟请求工具,有yapi,有ApiPost,好不好用在此不做评价。这里推荐使用BB-API
,功能全面,免费使用、资源无限制,自动生成接口文档,界面简洁大气。支持局域网部署,打造属于你、公司的HTTP 协议管理工具。
官网地址http://yun-api.com/