Arthas: 在windows下路径名带中文启动失败

Created on 14 Mar 2019  ·  11Comments  ·  Source: alibaba/arthas

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

环境信息

  • Arthas 版本: 3.1.0
  • 操作系统版本: Windows 7 SP1
  • 目标进程的JVM版本: jdk1.7.0_80
  • 执行arthas-boot的版本: 3.1.0

重现问题的步骤

  1. 下载arthas-packaging-3.1.0-bin.zip
    复制到内网系统,解压到E:\soft\Java开发工具
    注意内网系统是不能访问公网的。

  2. 在CMD执行命令行
    cd E:\soft\Java开发工具\arthas-packaging-3.1.0-bin
    java -jar arthas-boot.jar

  3. 选择注入到Tomcat进程

期望的结果

打开Arthas 交互操作的shell。

实际运行的结果

出现错误,程序终止。

E:\soft\Java开发工具\arthas-packaging-3.1.0-bin>java -jar arthas-boot.jar
[INFO] arthas-boot version: 3.1.0
[INFO] Found existing java process, please choose one and hit RETURN.
* [1]: 25360 E:\soft\portecle-1.7\portecle.jar
  [2]: 15292 com.szjlc.smt.search.SmtSearchApplication
  [3]: 3280
  [4]: 11276 org.jetbrains.jps.cmdline.Launcher
  [5]: 24472 com.szjlc.development.apidoc.ApiDocApplication
  [6]: 3788 org.apache.catalina.startup.Bootstrap
6
[ERROR] Can not read maven-metadata.xml from: https://maven.aliyun.com/repository/public/com/taobao/
arthas/arthas-packaging/maven-metadata.xml
[ERROR] Can not find Arthas under local: C:\Users\win7\.arthas\lib and remote: aliyun
bug

All 11 comments

arthas-boot 在启动时,会从当前目录下面查找 arthas其它的jar包,如果找不到,再从远程找。

是否中文目录影响的? 可以Debug 下 com.taobao.arthas.boot.Bootstrap

调试了一下,发现问题是检查中文路径的目录的ArthasHome失败了
com.taobao.arthas.boot.Bootstrap#verifyArthasHome

   private static void verifyArthasHome(String arthasHome) {
        File home = new File(arthasHome);
        if (home.isDirectory()) {
            String fileList[] = { "arthas-core.jar", "arthas-agent.jar", "arthas-spy.jar" };

            for (String fileName : fileList) {
                if (!new File(home, fileName).exists()) {
                    throw new IllegalArgumentException(
                                    fileName + " do not exist, arthas home: " + home.getAbsolutePath());
                }
            }
            return;
        }

        throw new IllegalArgumentException("illegal arthas home: " + home.getAbsolutePath());
    }

调试时arthasHome的值是:
E:\soft\Java%e5%bc%80%e5%8f%91%e5%b7%a5%e5%85%b7\arthas-packaging-3.1.0-bin
home.isDirectory() 为 false,验证失败,arthasHome为null,没有办法使用解压版本的jar。

😂,为啥windows下面判断目录失败。。 可以提交一个PR来修复下判断不?

1)Java在windows下获取jar资源路径存在一些问题,使用unicode转码了。
使用UrlDecoder.decode(home, "utf-8") 处理一下后,E:\soft\Java%e5%bc%80%e5%8f%91%e5%b7%a5%e5%85%b7\arthas-packaging-3.1.0-bin 路径恢复正常了
2)我看了一下,如果使用System.getProperty("user.dir") 是可以正确获取到当前的中文路径目录,是否增加一段处理,多检查一下工作目录?

System.getProperty("user.dir") 获取的是 working directory,这个不一定是 arthas-boot.jar的目录。

原来是踩过的坑: https://blog.csdn.net/hengyunabc/article/details/23174597 。。

要用 new File(url.toURI()); 来转换为File。 你改下这里试下?

String bootJarPath = codeSource.getLocation().getFile();

尝试添加一行转换代码,可以往下走,但到agent注入时又因为乱码失败了,这里有的不知道怎么下断点了。
bootJarPath = UrlDecoder.decode(bootJarPath , "utf-8");

@kylixs 参考这个: https://github.com/alibaba/arthas/issues/335 ,这个可以先不管,后面我找个 windows 环境研究下

VirtualMachine.loadAgent( jarpath, arg);
其中arg不能包含中文,否则传递到agent中时已经乱码。可以先将参数转码,然后传递给agent,在agent中解码一下

@kylixs 提个PR? 😄

感谢 @kylixs 的PR, Windows的同学可以用这个版本来测试下:

arthas-3.1.1-SNAPSHOT-bin.zip

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Feixu2015 picture Feixu2015  ·  4Comments

xiuqianli1996 picture xiuqianli1996  ·  4Comments

wenbeicai picture wenbeicai  ·  5Comments

EternalHao picture EternalHao  ·  4Comments

haifzhu picture haifzhu  ·  4Comments