Browse Source

Pull request #5229: REPORT-67847【迭代】windows环境,没有attach,放了tools的情况工程启动失败进入部署向导

Merge in CORE/base-third from ~ZHOUPING/base-third:feature/x to feature/x

* commit '42163ab043c0b18158cb541fc747d597920eb15a':
  REPORT-67847【迭代】windows环境,没有attach,放了tools的情况工程启动失败进入部署向导 【问题原因】放了tools.jar但没有attach.dll的时候虽然使用自定义类加载器,但是因为双亲委派的缘故,加载到了tools.jar中的virtualmachine 【改动思路】使用自定义的类加载器,并且打破双亲委派机制,判断为sun.tools.attach开头的包,都直接加载,不找父亲了
feature/x
zhouping 3 years ago
parent
commit
9779e6c096
  1. 25
      fine-third-jdk8/fine-mini-tools/tools-common/src/main/java/com/fr/third/utils/load/LibraryLoadProviderManager.java

25
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);
}
}
}

Loading…
Cancel
Save