From b0c54a65885de569cc20d4a1fb59b5372c73adcc Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Mon, 14 Oct 2013 16:01:58 -0400 Subject: [PATCH] Add parent class loader entries if possible ...otherwise you can see cryptic NoClassDefFound errors because the application class was loaded from the parent on the file system, but then it doesn't have access to the child loaders nested jars. --- .../boot/loader/PropertiesLauncher.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java index ab1a698832..65988e7fe0 100644 --- a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java +++ b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java @@ -21,7 +21,9 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; +import java.net.URISyntaxException; import java.net.URL; +import java.net.URLClassLoader; import java.net.URLConnection; import java.util.ArrayList; import java.util.Arrays; @@ -34,6 +36,7 @@ import org.springframework.boot.loader.archive.Archive; import org.springframework.boot.loader.archive.Archive.Entry; import org.springframework.boot.loader.archive.Archive.EntryFilter; import org.springframework.boot.loader.archive.ExplodedArchive; +import org.springframework.boot.loader.archive.JarFileArchive; import org.springframework.boot.loader.util.SystemPropertyUtils; /** @@ -318,9 +321,26 @@ public class PropertiesLauncher extends Launcher { this.logger.info("No directory found at " + path); } } + addParentClassLoaderEntries(lib); return lib; } + private void addParentClassLoaderEntries(List lib) throws IOException, + URISyntaxException { + ClassLoader parentClassLoader = getClass().getClassLoader(); + if (parentClassLoader instanceof URLClassLoader) { + URLClassLoader urlClassLoader = (URLClassLoader) parentClassLoader; + for (URL url : urlClassLoader.getURLs()) { + if (url.toString().endsWith(".jar") || url.toString().endsWith(".zip")) { + lib.add(0, new JarFileArchive(new File(url.toURI()))); + } + else { + lib.add(0, new ExplodedArchive(new File(url.getFile()))); + } + } + } + } + private String cleanupPath(String path) { path = path.trim(); // Always a directory