diff --git a/spring-boot-tools/spring-boot-loader/src/it/executable-jar/pom.xml b/spring-boot-tools/spring-boot-loader/src/it/executable-jar/pom.xml index 2fffa60044..b32c0e5d4c 100644 --- a/spring-boot-tools/spring-boot-loader/src/it/executable-jar/pom.xml +++ b/spring-boot-tools/spring-boot-loader/src/it/executable-jar/pom.xml @@ -63,7 +63,7 @@ - org.springframework.boot.load.JarLauncher + org.springframework.boot.loader.JarLauncher org.springframework.boot.load.it.jar.EmbeddedJarStarter diff --git a/spring-boot-tools/spring-boot-loader/src/it/executable-war/pom.xml b/spring-boot-tools/spring-boot-loader/src/it/executable-war/pom.xml index 193173d667..efa6e7b048 100644 --- a/spring-boot-tools/spring-boot-loader/src/it/executable-war/pom.xml +++ b/spring-boot-tools/spring-boot-loader/src/it/executable-war/pom.xml @@ -27,7 +27,7 @@ - org.springframework.boot.load.WarLauncher + org.springframework.boot.loader.WarLauncher org.springframework.boot.load.it.war.embedded.EmbeddedWarStarter diff --git a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/ExecutableArchiveLauncher.java b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/ExecutableArchiveLauncher.java index c50a13e6f5..ed93d835e0 100644 --- a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/ExecutableArchiveLauncher.java +++ b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/ExecutableArchiveLauncher.java @@ -16,8 +16,12 @@ package org.springframework.boot.loader; +import java.net.URL; +import java.net.URLClassLoader; import java.util.ArrayList; +import java.util.LinkedHashSet; import java.util.List; +import java.util.Set; import java.util.jar.JarEntry; import org.springframework.boot.loader.archive.Archive; @@ -64,6 +68,21 @@ public abstract class ExecutableArchiveLauncher extends Launcher { return archives; } + @Override + protected ClassLoader createClassLoader(URL[] urls) throws Exception { + Set copy = new LinkedHashSet(); + ClassLoader loader = getDefaultClassLoader(); + if (loader instanceof URLClassLoader) { + for (URL url : ((URLClassLoader) loader).getURLs()) { + copy.add(url); + } + } + for (URL url : urls) { + copy.add(url); + } + return super.createClassLoader(copy.toArray(new URL[copy.size()])); + } + /** * Determine if the specified {@link JarEntry} is a nested item that should be added * to the classpath. The method is called once for each entry. @@ -81,4 +100,20 @@ public abstract class ExecutableArchiveLauncher extends Launcher { protected void postProcessClassPathArchives(List archives) throws Exception { } + private static ClassLoader getDefaultClassLoader() { + ClassLoader cl = null; + try { + cl = Thread.currentThread().getContextClassLoader(); + } + catch (Throwable ex) { + // Cannot access thread context ClassLoader - falling back to system class + // loader... + } + if (cl == null) { + // No thread context class loader -> use class loader of this class. + cl = ExecutableArchiveLauncher.class.getClassLoader(); + } + return cl; + } + } diff --git a/spring-boot-tools/spring-boot-loader/src/test/resources/jars/app.jar b/spring-boot-tools/spring-boot-loader/src/test/resources/jars/app.jar index c7c485ae5d..fb02c02701 100644 Binary files a/spring-boot-tools/spring-boot-loader/src/test/resources/jars/app.jar and b/spring-boot-tools/spring-boot-loader/src/test/resources/jars/app.jar differ