Arthas 启动报 ClassNotFoundException com.sun.tools.attach.VirtualMachine

Arthas Java About 1,119 words

问题

使用Java11命令行方式java -jar启动Arthas,报错找不到VirtualMachine,具体信息如下:

PS C:\arthas-bin> java -jar .\arthas-boot.jar 2060
[INFO] arthas-boot version: 3.5.2
[INFO] arthas home: C:\arthas-bin
[INFO] Try to attach process 2060
[ERROR] Start arthas failed, exception stack trace:
java.lang.NoClassDefFoundError: com/sun/tools/attach/VirtualMachine
        at com.taobao.arthas.core.Arthas.attachAgent(Arthas.java:89)
        at com.taobao.arthas.core.Arthas.<init>(Arthas.java:26)
        at com.taobao.arthas.core.Arthas.main(Arthas.java:139)
Caused by: java.lang.ClassNotFoundException: com.sun.tools.attach.VirtualMachine
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
        at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
        ... 3 more
[ERROR] attach fail, targetPid: 2060

原因

Java9后采用模块化分包,默认java.base等一些常规模块可不需要requires就可使用,而jdk.internal则需要显示引入。

解决

可添加启动参数--add-opens,引入该模块。

java --add-opens=jdk.attach/com.sun.tools.attach=ALL-UNNAMED -jar .\arthas-boot.jar 2060
Views: 6,968 · Posted: 2021-07-23

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh