|
|
@ -26,6 +26,7 @@ public class LibraryLoadProviderManager { |
|
|
|
|
|
|
|
|
|
|
|
private static final String SRC_PATH_PREFIX = ""; |
|
|
|
private static final String SRC_PATH_PREFIX = ""; |
|
|
|
private static final String DES_CLASS_PREFIX = "/sun/tools/attach"; |
|
|
|
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 DES_LIBRARY_PREFIX = "/library"; |
|
|
|
private static final String FANRUAN_VM_TMPDIR_PROP = "fanruan.vm.tmpdir"; |
|
|
|
private static final String FANRUAN_VM_TMPDIR_PROP = "fanruan.vm.tmpdir"; |
|
|
|
|
|
|
|
|
|
|
@ -62,7 +63,7 @@ public class LibraryLoadProviderManager { |
|
|
|
if (classLoader == null) { |
|
|
|
if (classLoader == null) { |
|
|
|
String classpath = getTempToolsDirPath(); |
|
|
|
String classpath = getTempToolsDirPath(); |
|
|
|
File file = new File(classpath); |
|
|
|
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; |
|
|
|
return classLoader; |
|
|
@ -77,7 +78,7 @@ public class LibraryLoadProviderManager { |
|
|
|
FineLoggerFactory.getLogger().info("[CustomVM] get loading library path..."); |
|
|
|
FineLoggerFactory.getLogger().info("[CustomVM] get loading library path..."); |
|
|
|
String libName = libraryLoadProvider.libraryResource(); |
|
|
|
String libName = libraryLoadProvider.libraryResource(); |
|
|
|
String normalizePath = FilenameUtils.normalize(String.join("/", getTempToolsDirPath(), DES_LIBRARY_PREFIX, libName)); |
|
|
|
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; |
|
|
|
return normalizePath; |
|
|
|
} catch (IOException e) { |
|
|
|
} catch (IOException e) { |
|
|
|
FineLoggerFactory.getLogger().error(e, e.getMessage()); |
|
|
|
FineLoggerFactory.getLogger().error(e, e.getMessage()); |
|
|
@ -226,4 +227,24 @@ public class LibraryLoadProviderManager { |
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage()); |
|
|
|
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); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|