使用 mc 命令来内存编译修改过的代码时,报错:
[arthas@2432]$ jad --source-only demo.MathGame > /tmp/MathGame.java
[arthas@2432]$ mc /tmp/MathGame.java -d /tmp/
Memory compiler error, exception message: Can not load JavaCompiler from javax.tools.ToolProvider#getSystemJavaCompiler(), please confirm the application running in JDK not JRE., please check $HOME/logs/arthas/arthas.log for more details.
问题原因:
启动 arthas-boot.jar的时候使用的是默认的 opentjdk,而启动要监控的项目jar的是我自己安装的jdk,要确保 arthas-boot.jar与监控项目所启动的jdk保持一致!
总结:
1. 启动要监控的项目,这里使用的是我自己安装的 jdk
/usr/local/jdk1.8/bin/java -jar math-game.jar
2. 启动 arthas 时,与被监控项目的 jdk 保存一致。
执行成功
[arthas@3434]$ jad --source-only demo.MathGame > /tmp/MathGame.java
[arthas@3434]$ mc /tmp/MathGame.java -d /tmp/
Memory compiler output:
/tmp/demo/MathGame.class
Affect(row-cnt:1) cost in 795 ms.
补充,安装 mc 命令:
wget https://dl.min.io/client/mc/release/linux-amd64/mc
chmod +x ./mc
mv ./mc /usr/local/sbin/
把 mc文件放到 /usr/local/sbin/目录
中就可以在任何目录中使用 mc了。
至此结束!