Add URLs from parent classloader in executable jar
$ (cd spring-boot-tools; mvn clean install -DskipTests=true) $ (cd spring-boot-samples/spring-boot-sample-simple/; mvn clean package) $ java -jar spring-boot-samples/spring-boot-sample-simple/target/spring-boot-sample-simple-1.1.0.BUILD-SNAPSHOT.jar (vanilla executable jar archive: works) $ java -cp spring-boot-samples/spring-boot-sample-simple/target/spring-boot-sample-simple-1.1.0.BUILD-SNAPSHOT.jar:spring-boot-tools/spring-boot-loader/src/test/resources/jars/app.jar org.springframework.boot.loader.JarLauncher (jar archive plus vanilla plugin: works) $ (cd spring-boot-samples/spring-boot-sample-simple/target; rm -rf app && mkdir $_ && cd $_ && jar -xf ../*.jar) $ java -cp spring-boot-samples/spring-boot-sample-simple/target/app/ org.springframework.boot.loader.JarLauncher (exploded directory: works) $ java -cp spring-boot-tools/spring-boot-loader/s:spring-boot-tools/spring-boot-loader/src/test/resources/jars/app.jar org.springframework.boot.loader.JarLauncher (exploded directory with plugin jar: works) Potential fix for gh-529
This commit is contained in:
@@ -63,7 +63,7 @@
|
||||
</descriptors>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>org.springframework.boot.load.JarLauncher</mainClass>
|
||||
<mainClass>org.springframework.boot.loader.JarLauncher</mainClass>
|
||||
</manifest>
|
||||
<manifestEntries>
|
||||
<Start-Class>org.springframework.boot.load.it.jar.EmbeddedJarStarter</Start-Class>
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>org.springframework.boot.load.WarLauncher</mainClass>
|
||||
<mainClass>org.springframework.boot.loader.WarLauncher</mainClass>
|
||||
</manifest>
|
||||
<manifestEntries>
|
||||
<Start-Class>org.springframework.boot.load.it.war.embedded.EmbeddedWarStarter</Start-Class>
|
||||
|
||||
@@ -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<URL> copy = new LinkedHashSet<URL>();
|
||||
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<Archive> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user