From 3672c2c7a6434bcf0451e0377350c30615440629 Mon Sep 17 00:00:00 2001 From: hengyunabc Date: Tue, 27 Apr 2021 19:19:16 +0800 Subject: [PATCH] update lib name --- arthas-vmtool/pom.xml | 12 +++++----- .../src/main/java/arthas/Vmtool.java | 24 +++++++++++++++++++ .../src/test/java/arthas/VmtoolTest.java | 2 +- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/arthas-vmtool/pom.xml b/arthas-vmtool/pom.xml index c13775d75..f7e8799ea 100644 --- a/arthas-vmtool/pom.xml +++ b/arthas-vmtool/pom.xml @@ -25,7 +25,7 @@ macos -m64 - libArthasJniLibrary.dylib + libArthasJniLibrary-x64.dylib @@ -39,7 +39,7 @@ macos -m64 - libArthasJniLibrary.dylib + libArthasJniLibrary-amd64.dylib @@ -55,7 +55,7 @@ linux -m64 - libArthasJniLibrary.so + libArthasJniLibrary-x64.so @@ -69,7 +69,7 @@ linux -m64 - libArthasJniLibrary.so + libArthasJniLibrary-amd64.so @@ -85,7 +85,7 @@ windows -m64 - ArthasJniLibrary.dll + libArthasJniLibrary-x64.dll @@ -99,7 +99,7 @@ windows -m64 - ArthasJniLibrary.dll + libArthasJniLibrary-amd64.dll diff --git a/arthas-vmtool/src/main/java/arthas/Vmtool.java b/arthas-vmtool/src/main/java/arthas/Vmtool.java index 1f0c21ab3..ad72fa649 100644 --- a/arthas-vmtool/src/main/java/arthas/Vmtool.java +++ b/arthas-vmtool/src/main/java/arthas/Vmtool.java @@ -2,6 +2,8 @@ package arthas; import java.util.ArrayList; +import com.taobao.arthas.common.OSUtils; + /** * @author ZhangZiCheng 2021-02-12 * @author hengyunabc 2021-04-26 @@ -14,6 +16,24 @@ public class Vmtool implements VMtoolMXBean { */ public final static String JNI_LIBRARY_NAME = "ArthasJniLibrary"; + private static String libName = null; + static { + if (OSUtils.isMac()) { + libName = "libArthasJniLibrary-x64.dylib"; + } + if (OSUtils.isLinux()) { + libName = "libArthasJniLibrary-x64.so"; + if (OSUtils.isArm32()) { + libName = "libArthasJniLibrary-arm.so"; + } else if (OSUtils.isArm64()) { + libName = "libArthasJniLibrary-aarch64.so"; + } + } + if (OSUtils.isWindows()) { + libName = "libArthasJniLibrary-x64.dll"; + } + } + private static Vmtool instance; private Vmtool() { @@ -38,6 +58,10 @@ public class Vmtool implements VMtoolMXBean { return instance; } + public static String detectLibName() { + return libName; + } + /** * 检测jni-lib是否正常,如果正常,应该输出OK */ diff --git a/arthas-vmtool/src/test/java/arthas/VmtoolTest.java b/arthas-vmtool/src/test/java/arthas/VmtoolTest.java index fe1592557..5a2b63553 100644 --- a/arthas-vmtool/src/test/java/arthas/VmtoolTest.java +++ b/arthas-vmtool/src/test/java/arthas/VmtoolTest.java @@ -27,7 +27,7 @@ public class VmtoolTest { String path = Vmtool.class.getProtectionDomain().getCodeSource().getLocation().getPath(); System.err.println(path); - String libPath = new File(path, System.mapLibraryName(Vmtool.JNI_LIBRARY_NAME)).getAbsolutePath(); + String libPath = new File(path, Vmtool.detectLibName()).getAbsolutePath(); Vmtool vmtool = Vmtool.getInstance(libPath); //调用native方法,获取已加载的类,不包括小类型(如int)