Commit 08225895 authored by Andy Wilkinson's avatar Andy Wilkinson

Fall back to JVM's class path when finding jars with static resources

Previously, StaticResourceJars would only find jars with
META-INF/resources content if it had been loaded by a URLClassLoader.
This is not the case on Java 9 and, as a result, static content in
META-INF/resources of any jars on the class path was not found.

This commit updates StaticResourceJars to fall back to using the
JVM's class path to find static resource jars when it was loaded by
a ClassLoader that is not a URLClassLoader.

Closes gh-10455
parent ce77f48c
......@@ -63,26 +63,4 @@
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>java9</id>
<activation>
<jdk>9</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/EmbeddedServletContainerJarDevelopmentIntegrationTests.java</exclude>
<exclude>**/EmbeddedServletContainerWarDevelopmentIntegrationTests.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
......@@ -18,7 +18,9 @@ package org.springframework.boot.web.servlet.server;
import java.io.File;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.net.JarURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLConnection;
......@@ -43,9 +45,25 @@ class StaticResourceJars {
addUrl(urls, url);
}
}
else {
for (String entry : ManagementFactory.getRuntimeMXBean().getClassPath()
.split(File.pathSeparator)) {
addUrl(urls, toUrl(entry));
}
}
return urls;
}
private URL toUrl(String classPathEntry) {
try {
return new File(classPathEntry).toURI().toURL();
}
catch (MalformedURLException ex) {
throw new IllegalArgumentException(
"URL could not be created from '" + classPathEntry + "'", ex);
}
}
private void addUrl(List<URL> urls, URL url) {
try {
if ("file".equals(url.getProtocol())) {
......
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