arthas icon indicating copy to clipboard operation
arthas copied to clipboard

启动报错

Open fanyuanhang opened this issue 11 months ago • 2 comments

  • [x] 我已经在 issues 里搜索,没有重复的issue。

环境信息

  • arthas-boot.jar 或者 as.sh 的版本: xxx
  • Arthas 版本: xxx
  • 操作系统版本: xxx
  • 目标进程的JVM版本: xxx
  • 执行arthas-boot的版本: xxx

重现问题的步骤

  1. xxx
  2. xxx
  3. xxx

期望的结果

What do you expected from the above steps?

实际运行的结果

实际运行结果,最好有详细的日志,异常栈。尽量贴文本。

把异常信息贴到这里
root@iZ2zeclgm6tesstqavptwwZ local]# java -Darthas.debug=true -jar arthas-boot.jar
[INFO] JAVA_HOME: /usr/lib/jvm/jdk1.8.0_202/jre
[INFO] arthas-boot version: 4.0.4
[INFO] Found existing java process, please choose one and input the serial number of the process, eg : 1. Then hit ENTER.
* [1]: 19502 math-game.jar
1
[INFO] arthas home: /root/.arthas/lib/4.0.4/arthas
[INFO] Try to attach process 19502
Picked up JAVA_TOOL_OPTIONS: 
com.sun.tools.attach.AttachOperationFailedException: java.lang.NoClassDefFoundError: Could not initialize class sun.util.calendar.ZoneInfoFile
        at sun.tools.attach.LinuxVirtualMachine.execute(LinuxVirtualMachine.java:229)
        at sun.tools.attach.HotSpotVirtualMachine.executeCommand(HotSpotVirtualMachine.java:261)
        at sun.tools.attach.HotSpotVirtualMachine.getSystemProperties(HotSpotVirtualMachine.java:144)
        at com.taobao.arthas.core.Arthas.attachAgent(Arthas.java:105)
        at com.taobao.arthas.core.Arthas.<init>(Arthas.java:27)
        at com.taobao.arthas.core.Arthas.main(Arthas.java:161)
[ERROR] Start arthas failed, exception stack trace: 
[ERROR] attach fail, targetPid: 19502

fanyuanhang avatar Jan 09 '25 06:01 fanyuanhang

This error: java.lang.NoClassDefFoundError: Could not initialize class sun.util.calendar.ZoneInfoFile

usually occurs due to a corrupted or incomplete Java timezone configuration on your server. It's a known JDK-related issue rather than Arthas itself

Quick Solution (Simple fix): Set the Java timezone explicitly by adding this JVM argument: java -Duser.timezone=UTC -Darthas.debug=true -jar arthas-boot.jar

or ensure your system timezone data is valid: export TZ=UTC java -Darthas.debug=true -jar arthas-boot.jar

Reason for the Issue (briefly): This exception (NoClassDefFoundError: sun.util.calendar.ZoneInfoFile) typically occurs because Java fails to load or initialize timezone information from the system or its internal configuration.

The above fix resolves the issue immediately.

sheikmca avatar Mar 09 '25 04:03 sheikmca

你可以使用官方的那个教程中的演示试试,是可以正常运行的,你这个问题主要就是以下几个问题导致的 从你提供的异常信息 com.sun.tools.attach.AttachOperationFailedException: java.lang.NoClassDefFoundError: Could not initialize class sun.util.calendar.ZoneInfoFile 来看,这很可能是由于 JDK 相关的配置或文件存在问题导致 Arthas 无法成功 attach 到目标进程。以下是一些可能的原因和解决办法:

  1. JDK 完整性问题

    • 原因NoClassDefFoundError 通常表示类在编译时可以找到,但在运行时找不到,这里提示 sun.util.calendar.ZoneInfoFile 类无法初始化,可能是 JDK 的某些文件损坏或缺失,影响到了 Arthas 对目标进程的 attach 操作。
    • 解决办法:重新安装 JDK,确保安装过程完整且没有出现错误。安装完成后,检查 JAVA_HOME 环境变量是否正确指向新安装的 JDK 路径。
  2. 环境变量配置问题

    • 原因:虽然你已经设置了 JAVA_HOME 环境变量,但可能还存在其他与 JDK 相关的环境变量配置不正确,或者 JAVA_TOOL_OPTIONS 变量影响了 Arthas 的运行。
    • 解决办法:检查所有与 JDK 相关的环境变量,如 PATH 中是否正确包含了 JDK 的 bin 目录路径。同时,可以尝试清空 JAVA_TOOL_OPTIONS 变量(因为你看到 Picked up JAVA_TOOL_OPTIONS: 提示,不确定这个变量是否对 Arthas 有影响),然后重新运行 arthas-boot.jar
  3. 类加载顺序问题

    • 原因:在某些情况下,类加载的顺序可能会导致 NoClassDefFoundError 错误。例如,可能存在其他类库与 JDK 中的类库冲突,或者加载顺序不符合预期。
    • 解决办法:检查项目中引用的所有类库,确保没有与 JDK 类库冲突的情况。如果可能的话,尝试更新或替换一些可能存在问题的类库。
  4. 权限问题

    • 原因:在尝试 attach 到目标进程时,可能由于权限不足导致操作失败。Arthas 需要有足够的权限来与目标 Java 进程进行交互。
    • 解决办法:确保你是以具有足够权限的用户身份运行 arthas-boot.jar。如果是在服务器上运行,可以尝试使用 root 用户或者给运行 Arthas 的用户赋予适当的权限。
  5. Arthas 版本兼容性问题

    • 原因:当前使用的 Arthas 4.0.4 版本可能与你所使用的 JDK 版本存在兼容性问题。
    • 解决办法:可以尝试升级或降级 Arthas 的版本,查看是否能够解决问题。可以从 Arthas 的官方网站获取不同版本的下载链接。

按照以上步骤逐一排查和解决,希望能够帮助你解决 Arthas 无法成功 attach 到目标进程的问题。

sunheyi6 avatar Mar 15 '25 08:03 sunheyi6