arthas 源码构建

arthas 源码构建

git下载代码

git clone https://github.com/alibaba/arthas.git

若github被墙,可以在gitee搜索下载

maven clean

可以在项目目录执行 mvn clean , ide可以执行界面执行

arthas 源码构建_第1张图片

maven package

可以在项目目录执行mvn package

arthas 源码构建_第2张图片

问题记录

javah 命令不存在

pom文件位于/arthas/arthas-vmtool/pom.xml,属于arthas-vmtool模块,这个模块中有c代码,编译后需要java native使用,所以需要使用javah 命令,但是在高版本的jdk中已经使用javac -h进行代替,所以在java环境的bin目录中已经不存在javah 命令(初始版本使用jdk11编译会报错)。

[ERROR] Failed to execute goal org.codehaus.mojo:native-maven-plugin:1.0-alpha-11:javah (javah) on project arthas-vmtool: Error running javah command: Error executing command line: Error while executing process. Cannot run program "javah" (in directory "/home/dark/IdeaProjects/arthas/arthas-vmtool"): error=2, 没有那个文件或目录 -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.

为了解决没有javah 命令,我切换为jdk8,并检查bin目录下的确存在javah,则问题得以解决。但是其他模块却需要更高版本的java,所以查阅文档后,发现native-maven-plugin可以配置参数javahPath指定javah命令的位置,所以我在使用jdk11时,指定了jdk8的javah命令,在pom.xml中如下改造:

<plugin>
                <groupId>org.codehaus.mojogroupId>
                <artifactId>native-maven-pluginartifactId>
                <version>1.0-alpha-11version>
                <extensions>trueextensions>
                <configuration>
                    
                    
                    <javahPath>/home/dark/.jdks/jdk1.8.0_202/bin/javahjavahPath>
                    <javahIncludes>
                        <javahInclude>
                            <className>arthas.VmToolclassName>
                        javahInclude>
                    javahIncludes>
                    <jdkIncludePath>${project.basedir}/src/main/native/headjdkIncludePath>
                    <javahOS>${os_name}javahOS>
                    <sources>
                        <source>
                            <directory>src/main/native/srcdirectory>
                            <fileNames>
                                <fileName>jni-library.cppfileName>
                            fileNames>
                 javahPath       source>
                    sources>

                    <compilerProvider>generic-classiccompilerProvider>
                    <compilerExecutable>g++compilerExecutable>
                    <compilerStartOptions>
                        <compilerStartOption>${os_arch_option}compilerStartOption>
                        <compilerStartOption>-fpiccompilerStartOption>
                        <compilerStartOption>-sharedcompilerStartOption>
                        <compilerStartOption>-ocompilerStartOption>
                    compilerStartOptions>

                    <linkerOutputDirectory>targetlinkerOutputDirectory>
                    <linkerExecutable>g++linkerExecutable>
                    <linkerStartOptions>
                        <linkerStartOption>${os_arch_option}linkerStartOption>
                        <linkerStartOption>-fpiclinkerStartOption>
                        <linkerStartOption>-sharedlinkerStartOption>
                        
                    linkerStartOptions>
                    <linkerEndOptions>
                        <linkerEndOption>-o ${project.build.directory}/${lib_name}linkerEndOption>
                    linkerEndOptions>
                configuration>
                <executions>
                    <execution>
                        <id>javahid>
                        <phase>compilephase>
                        <goals>
                            <goal>javahgoal>
                            <goal>initializegoal>
                            <goal>compilegoal>
                            <goal>linkgoal>
                        goals>
                    execution>arthas源码构建
                executions>
            plugin>

jfr包找不到

jfr是jdk下的包,但是低版本(jdk 8)中许多类不存在,导致许多类不存在报错,在构建arthas-core模块会失败。

arthas 源码构建_第3张图片

所以要设置jdk环境为jdk 11,如下图:

arthas 源码构建_第4张图片

PS

若有一个直接可用的jdk版本麻烦通知一下,折腾起来也挺麻烦。

你可能感兴趣的:(arthas,arthas)