Commit b0c54a65 authored by Dave Syer's avatar Dave Syer

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.
parent 114b7a5e
...@@ -21,7 +21,9 @@ import java.io.FileInputStream; ...@@ -21,7 +21,9 @@ import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLConnection; import java.net.URLConnection;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
...@@ -34,6 +36,7 @@ import org.springframework.boot.loader.archive.Archive; ...@@ -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.Entry;
import org.springframework.boot.loader.archive.Archive.EntryFilter; import org.springframework.boot.loader.archive.Archive.EntryFilter;
import org.springframework.boot.loader.archive.ExplodedArchive; import org.springframework.boot.loader.archive.ExplodedArchive;
import org.springframework.boot.loader.archive.JarFileArchive;
import org.springframework.boot.loader.util.SystemPropertyUtils; import org.springframework.boot.loader.util.SystemPropertyUtils;
/** /**
...@@ -318,9 +321,26 @@ public class PropertiesLauncher extends Launcher { ...@@ -318,9 +321,26 @@ public class PropertiesLauncher extends Launcher {
this.logger.info("No directory found at " + path); this.logger.info("No directory found at " + path);
} }
} }
addParentClassLoaderEntries(lib);
return lib; return lib;
} }
private void addParentClassLoaderEntries(List<Archive> 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) { private String cleanupPath(String path) {
path = path.trim(); path = path.trim();
// Always a directory // Always a directory
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment