Do not set launcher CL as parent
This commit is contained in:
committed by
Mark Fisher
parent
e95e20a718
commit
8d7ebe536e
@@ -16,7 +16,12 @@
|
||||
|
||||
package org.springframework.boot.loader;
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.boot.loader.archive.Archive;
|
||||
import org.springframework.boot.loader.util.AsciiBytes;
|
||||
@@ -31,8 +36,12 @@ public class ModuleJarLauncher extends ExecutableArchiveLauncher {
|
||||
|
||||
private static final AsciiBytes LIB = new AsciiBytes("lib/");
|
||||
|
||||
private final InputArgumentsJavaAgentDetector javaAgentDetector;
|
||||
|
||||
|
||||
public ModuleJarLauncher(Archive archive) {
|
||||
super(archive);
|
||||
this.javaAgentDetector = new InputArgumentsJavaAgentDetector();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,8 +54,51 @@ public class ModuleJarLauncher extends ExecutableArchiveLauncher {
|
||||
archives.add(0, getArchive());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void launch(String[] args) {
|
||||
super.launch(args);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ClassLoader createClassLoader(URL[] urls) throws Exception {
|
||||
Set<URL> copy = new LinkedHashSet<URL>(urls.length);
|
||||
ClassLoader loader = getDefaultClassLoader();
|
||||
if (loader instanceof URLClassLoader) {
|
||||
for (URL url : ((URLClassLoader) loader).getURLs()) {
|
||||
if (addDefaultClassloaderUrl(urls, url)) {
|
||||
copy.add(url);
|
||||
}
|
||||
}
|
||||
}
|
||||
Collections.addAll(copy, urls);
|
||||
return new LaunchedURLClassLoader(copy.toArray(new URL[copy.size()]), null);
|
||||
}
|
||||
|
||||
|
||||
private boolean addDefaultClassloaderUrl(URL[] urls, URL url) {
|
||||
String jarUrl = "jar:" + url + "!/";
|
||||
for (URL nestedUrl : urls) {
|
||||
if (nestedUrl.equals(url) || nestedUrl.toString().equals(jarUrl)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return !this.javaAgentDetector.isJavaAgentJar(url);
|
||||
}
|
||||
|
||||
private static ClassLoader getDefaultClassLoader() {
|
||||
ClassLoader classloader = null;
|
||||
try {
|
||||
classloader = Thread.currentThread().getContextClassLoader();
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
// Cannot access thread context ClassLoader - falling back to system class
|
||||
// loader...
|
||||
}
|
||||
if (classloader == null) {
|
||||
// No thread context class loader -> use class loader of this class.
|
||||
classloader = ExecutableArchiveLauncher.class.getClassLoader();
|
||||
}
|
||||
return classloader;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user