From 42163ab043c0b18158cb541fc747d597920eb15a Mon Sep 17 00:00:00 2001 From: zhouping Date: Tue, 15 Mar 2022 21:57:53 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-67847=E3=80=90=E8=BF=AD=E4=BB=A3?= =?UTF-8?q?=E3=80=91windows=E7=8E=AF=E5=A2=83=EF=BC=8C=E6=B2=A1=E6=9C=89at?= =?UTF-8?q?tach=EF=BC=8C=E6=94=BE=E4=BA=86tools=E7=9A=84=E6=83=85=E5=86=B5?= =?UTF-8?q?=E5=B7=A5=E7=A8=8B=E5=90=AF=E5=8A=A8=E5=A4=B1=E8=B4=A5=E8=BF=9B?= =?UTF-8?q?=E5=85=A5=E9=83=A8=E7=BD=B2=E5=90=91=E5=AF=BC=20=E3=80=90?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E5=8E=9F=E5=9B=A0=E3=80=91=E6=94=BE=E4=BA=86?= =?UTF-8?q?tools.jar=E4=BD=86=E6=B2=A1=E6=9C=89attach.dll=E7=9A=84?= =?UTF-8?q?=E6=97=B6=E5=80=99=E8=99=BD=E7=84=B6=E4=BD=BF=E7=94=A8=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E7=B1=BB=E5=8A=A0=E8=BD=BD=E5=99=A8=EF=BC=8C?= =?UTF-8?q?=E4=BD=86=E6=98=AF=E5=9B=A0=E4=B8=BA=E5=8F=8C=E4=BA=B2=E5=A7=94?= =?UTF-8?q?=E6=B4=BE=E7=9A=84=E7=BC=98=E6=95=85=EF=BC=8C=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E5=88=B0=E4=BA=86tools.jar=E4=B8=AD=E7=9A=84virtualmachine=20?= =?UTF-8?q?=E3=80=90=E6=94=B9=E5=8A=A8=E6=80=9D=E8=B7=AF=E3=80=91=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E8=87=AA=E5=AE=9A=E4=B9=89=E7=9A=84=E7=B1=BB=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E5=99=A8=EF=BC=8C=E5=B9=B6=E4=B8=94=E6=89=93=E7=A0=B4?= =?UTF-8?q?=E5=8F=8C=E4=BA=B2=E5=A7=94=E6=B4=BE=E6=9C=BA=E5=88=B6=EF=BC=8C?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E4=B8=BAsun.tools.attach=E5=BC=80=E5=A4=B4?= =?UTF-8?q?=E7=9A=84=E5=8C=85=EF=BC=8C=E9=83=BD=E7=9B=B4=E6=8E=A5=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=EF=BC=8C=E4=B8=8D=E6=89=BE=E7=88=B6=E4=BA=B2=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../load/LibraryLoadProviderManager.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/fine-third-jdk8/fine-mini-tools/tools-common/src/main/java/com/fr/third/utils/load/LibraryLoadProviderManager.java b/fine-third-jdk8/fine-mini-tools/tools-common/src/main/java/com/fr/third/utils/load/LibraryLoadProviderManager.java index 620e87246..dc1ec5059 100644 --- a/fine-third-jdk8/fine-mini-tools/tools-common/src/main/java/com/fr/third/utils/load/LibraryLoadProviderManager.java +++ b/fine-third-jdk8/fine-mini-tools/tools-common/src/main/java/com/fr/third/utils/load/LibraryLoadProviderManager.java @@ -26,6 +26,7 @@ public class LibraryLoadProviderManager { private static final String SRC_PATH_PREFIX = ""; private static final String DES_CLASS_PREFIX = "/sun/tools/attach"; + private static final String CLASS_PACKAGE_NAME = "sun.tools.attach"; private static final String DES_LIBRARY_PREFIX = "/library"; private static final String FANRUAN_VM_TMPDIR_PROP = "fanruan.vm.tmpdir"; @@ -62,7 +63,7 @@ public class LibraryLoadProviderManager { if (classLoader == null) { String classpath = getTempToolsDirPath(); File file = new File(classpath); - classLoader = new URLClassLoader(new URL[]{file.toURI().toURL()}, this.getClass().getClassLoader()); + classLoader = new CustomURLClassLoader(new URL[]{file.toURI().toURL()}, this.getClass().getClassLoader()); } } return classLoader; @@ -77,7 +78,7 @@ public class LibraryLoadProviderManager { FineLoggerFactory.getLogger().info("[CustomVM] get loading library path..."); String libName = libraryLoadProvider.libraryResource(); String normalizePath = FilenameUtils.normalize(String.join("/", getTempToolsDirPath(), DES_LIBRARY_PREFIX, libName)); - FineLoggerFactory.getLogger().info("[CustomVM] loading library path:{}" + normalizePath); + FineLoggerFactory.getLogger().info("[CustomVM] loading library path:{}", normalizePath); return normalizePath; } catch (IOException e) { FineLoggerFactory.getLogger().error(e, e.getMessage()); @@ -226,4 +227,24 @@ public class LibraryLoadProviderManager { FineLoggerFactory.getLogger().error(e.getMessage()); } } + + private class CustomURLClassLoader extends URLClassLoader { + + CustomURLClassLoader(URL[] urls, ClassLoader parent) { + super(urls, parent); + } + + @Override + public Class loadClass(String className) throws ClassNotFoundException { + if (className.startsWith(CLASS_PACKAGE_NAME)) { + //有tools.jar但是不存在attach的情况下,sun.tools.attach.* 这些类要打破双亲委派机制直接加载自定义的 + Class loadedClass = findLoadedClass(className); + if (loadedClass == null) { + FineLoggerFactory.getLogger().info("{} load from custom urls directly", className); + return findClass(className); + } + } + return super.loadClass(className); + } + } }