Skip to content

Commit 0822589

Browse files
committed
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
1 parent ce77f48 commit 0822589

File tree

2 files changed

+18
-22
lines changed
  • spring-boot-integration-tests/spring-boot-integration-tests-embedded-servlet-container
  • spring-boot/src/main/java/org/springframework/boot/web/servlet/server

2 files changed

+18
-22
lines changed

spring-boot-integration-tests/spring-boot-integration-tests-embedded-servlet-container/pom.xml

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -63,26 +63,4 @@
6363
</plugin>
6464
</plugins>
6565
</build>
66-
<profiles>
67-
<profile>
68-
<id>java9</id>
69-
<activation>
70-
<jdk>9</jdk>
71-
</activation>
72-
<build>
73-
<plugins>
74-
<plugin>
75-
<groupId>org.apache.maven.plugins</groupId>
76-
<artifactId>maven-surefire-plugin</artifactId>
77-
<configuration>
78-
<excludes>
79-
<exclude>**/EmbeddedServletContainerJarDevelopmentIntegrationTests.java</exclude>
80-
<exclude>**/EmbeddedServletContainerWarDevelopmentIntegrationTests.java</exclude>
81-
</excludes>
82-
</configuration>
83-
</plugin>
84-
</plugins>
85-
</build>
86-
</profile>
87-
</profiles>
8866
</project>

spring-boot/src/main/java/org/springframework/boot/web/servlet/server/StaticResourceJars.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
import java.io.File;
2020
import java.io.IOException;
21+
import java.lang.management.ManagementFactory;
2122
import java.net.JarURLConnection;
23+
import java.net.MalformedURLException;
2224
import java.net.URL;
2325
import java.net.URLClassLoader;
2426
import java.net.URLConnection;
@@ -43,9 +45,25 @@ public final List<URL> getUrls() {
4345
addUrl(urls, url);
4446
}
4547
}
48+
else {
49+
for (String entry : ManagementFactory.getRuntimeMXBean().getClassPath()
50+
.split(File.pathSeparator)) {
51+
addUrl(urls, toUrl(entry));
52+
}
53+
}
4654
return urls;
4755
}
4856

57+
private URL toUrl(String classPathEntry) {
58+
try {
59+
return new File(classPathEntry).toURI().toURL();
60+
}
61+
catch (MalformedURLException ex) {
62+
throw new IllegalArgumentException(
63+
"URL could not be created from '" + classPathEntry + "'", ex);
64+
}
65+
}
66+
4967
private void addUrl(List<URL> urls, URL url) {
5068
try {
5169
if ("file".equals(url.getProtocol())) {

0 commit comments

Comments
 (0)