[alibaba/arthas][Question]修改源码后怎么成功打包以便debug修改效果

2022-10-14 31 views
3
环境信息
  • Arthas 版本: 源码master分支
  • 操作系统版本: win7,32位
  • JVM版本: jdk8
重现问题的步骤
  1. 源码根目录执行mvn -DskipTests clean package
期望的结果

打包成功

实际运行的结果

打包失败:arthas-vmtool 模块编译失败。

[INFO] --- native-maven-plugin:1.0-alpha-11:compile (javah) @ arthas-vmtool ---
[INFO] cmd.exe /X /C "g++ -fpic -shared -o -IE:\IdeaProjects\arthas\arthas-vmtool\src\main\native\src -IE:\IdeaProjects\arthas\arthas-vmtool\target\generated-sources\annotations -IE:\IdeaProjects\arthas\arthas-vmtool\target\native\j
avah -oE:\IdeaProjects\arthas\arthas-vmtool\target\objs\jni-library.obj -c E:\IdeaProjects\arthas\arthas-vmtool\src\main\native\src\jni-library.cpp"
E:\IdeaProjects\arthas\arthas-vmtool\src\main\native\src\jni-library.cpp:2:17: fatal error: jni.h: No such file or directory
 #include <jni.h>
                 ^
compilation terminated.
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for arthas-all 3.6.6:
[INFO]
[INFO] arthas-all ......................................... SUCCESS [  3.385 s]
[INFO] web-ui ............................................. SUCCESS [02:18 min]
[INFO] math-game .......................................... SUCCESS [  7.597 s]
[INFO] arthas-common ...................................... SUCCESS [  2.699 s]
[INFO] arthas-spy ......................................... SUCCESS [  1.373 s]
[INFO] arthas-vmtool ...................................... FAILURE [ 11.981 s]
[INFO] arthas-tunnel-common ............................... SKIPPED
[INFO] arthas-tunnel-client ............................... SKIPPED
[INFO] arthas-memorycompiler .............................. SKIPPED
[INFO] arthas-core ........................................ SKIPPED
[INFO] arthas-agent ....................................... SKIPPED
[INFO] arthas-client ...................................... SKIPPED
[INFO] arthas-boot ........................................ SKIPPED
[INFO] arthas-agent-attach ................................ SKIPPED
[INFO] arthas-site ........................................ SKIPPED
[INFO] arthas-packaging ................................... SKIPPED
[INFO] arthas-spring-boot-starter ......................... SKIPPED
[INFO] arthas-tunnel-server ............................... SKIPPED
[INFO] arthas-testcase .................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  02:47 min
[INFO] Finished at: 2022-10-14T14:19:10+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:native-maven-plugin:1.0-alpha-11:compile (javah) on project arthas-vmtool: Error executing command line. Exit code:1

如何解决,是不是不支持windows7 32位?

回答

2

已经安装gcc(另外还需要安装g++,因为 1665853102896 )。


尝试忽略掉打包失败的模块mvn -DskipTests --fail-at-end clean package但是vmtool构建失败会导致arthas-core构建被忽略,估计是依赖了:

[INFO] Skipping arthas-core
[INFO] This project has been banned from the build due to previous failures.【备注:此前失败的只有arthas-vmtool】

另外arthas-packaging、arthas-spring-boot-starter也失败了,不知道是受arthas-site影响,还是受arthas-vmtool影响?)。 1665854367616


尝试打包指定模块(排除arthas-vmtool)mvn -DskipTests -pl ../arthas,web-ui,math-game,common,spy,tunnel-common,tunnel-client,core,agent,client,memorycompiler,boot,arthas-agent-attach,arthas-spring-boot-starter,tunnel-server,testcase,site,packaging clean package但是构建arthas-core失败(因为jdk.jfr是jdk9引入的,但编译采用的jdk8):

[ERROR] /E:/IdeaProjects/arthas/core/src/main/java/com/taobao/arthas/core/command/basic1000/JFRCommand.java:[14,1] 程序包jdk.jfr不存在
[ERROR] /E:/IdeaProjects/arthas/core/src/main/java/com/taobao/arthas/core/command/basic1000/JFRCommand.java:[51,30] 找不到符号
  符号:   类 Recording
  位置: 类 com.taobao.arthas.core.command.basic1000.JFRCommand
[ERROR] /E:/IdeaProjects/arthas/core/src/main/java/com/taobao/arthas/core/command/basic1000/JFRCommand.java:[367,18] 找不到符号
  符号:   类 Recording
  位置: 类 com.taobao.arthas.core.command.basic1000.JFRCommand
[ERROR] /E:/IdeaProjects/arthas/core/src/main/java/com/taobao/arthas/core/command/basic1000/JFRCommand.java:[377,33] 找不到符号
  符号:   类 Recording
  位置: 类 com.taobao.arthas.core.command.basic1000.JFRCommand
[INFO] 4 errors
4
[INFO] cmd.exe /X /C "g++ -fpic -shared -o -IE:\IdeaProjects\arthas\arthas-vmtool\src\main\native\src -IE:\IdeaProjects\arthas\arthas-vmtool\target\generated-sources\annotations -IE:\IdeaProjects\arthas\arthas-vmtool\target\native\j
avah -oE:\IdeaProjects\arthas\arthas-vmtool\target\objs\jni-library.obj -c E:\IdeaProjects\arthas\arthas-vmtool\src\main\native\src\jni-library.cpp"
E:\IdeaProjects\arthas\arthas-vmtool\src\main\native\src\jni-library.cpp:2:17: fatal error: jni.h: No such file or directory
 #include <jni.h>
                 ^

看了你打包报错的信息,是没有include项目中头文件~\arthas\arthas-vmtool\src\main\native\head~\arthas\arthas-vmtool\src\main\native\head\windows,这本应该由插件native-maven-plugin自动include。于是检查了arthas-vmtool模块pom文件配置,找到了可能导致该问题的原因。

分析:pom中虽然给插件native-maven-plugin配置了头文件路径<jdkIncludePath>...</jdkIncludePath>,但是没有生效。因为该配置生效的前提是<javahOS>有效(对此可以看下官方对javahOS的说明,在native-maven-plugin-1.0-alpha-11.jar\META-INF\maven\plugin.xml文件中:<description>Javah OS name. ${jdkIncludePath} and ${jdkIncludePath}/${javaOS} are added to system include path when this field is set</description>)。 <javahOS>没有生效是由于该pom配置了根据操作系统自动激活的profile,虽然有针对windows的,但是架构必须是amd64,而32位即x86架构的激活不了,导致${os_name}获取不到,也就使得<javahOS>${os_name}</javahOS>失效。

解决方案:你可以试试按照下面修改下该pom中windows的这段profile,再重新打包。

...
 <!-- windows -->
<!-- 这段新增的profile是windows系统通用,即只要是windows系统,都能激活,保证os_name有效 -->
<profile>
    <id>windows</id>
    <activation>
        <os>
            <family>windows</family>
        </os>
    </activation>
    <properties>
        <os_name>windows</os_name>
    </properties>
</profile>
<!-- 这段新增的profile是针对windows x86系统,使在该系统下时os_arch_option和lib_name有效-->
<profile>
    <id>windows-32</id>
    <activation>
        <os>
            <family>windows</family>
            <arch>x86</arch>
        </os>
    </activation>
    <properties>
        <os_arch_option>-m32</os_arch_option>
        <lib_name>libArthasJniLibrary-x64.dll</lib_name>
    </properties>
</profile>
<!-- 这段是原本的profile,针对windows amd64系统的,做了点修改:将os_name提取到上面windows通用的profile中-->
<profile>
    <id>windows-amd64</id>
    <activation>
        <os>
            <family>windows</family>
            <arch>amd64</arch>
        </os>
    </activation>
    <properties>
        <os_arch_option>-m64</os_arch_option>
        <lib_name>libArthasJniLibrary-x64.dll</lib_name>
    </properties>
    ...
</profile>
8

@pandaapo 非常感谢!arthas-vmtool模块终于打包成功了!!!arthas-core模块也跟着成功了!

3

@pandaapo 能提交个PR修改下这部分配置吗?方便win32的用户。

5

windows 10已经不支持32位了,感觉这个支持意义不大。

2

也许是我没有大佬的思维高度,但感觉还是可以再考虑一下。个人愚见:毕竟Arthas该神器也能在win32位上大放异彩,毕竟除了win 7还有win 8嘛,而且该增量配置也不影响win64位,而且OpenJDK目前到最新的jdk 19还在支持win32位。

9

有一定道理,需要在win32的使用vmtool的用户可以自己编译。

@pandaapo 麻烦帮忙提个PR,支持win32打包?