Skip to content

Commit 6c7289b

Browse files
committed
Allow META-INF/resources in WAR classes folder
Update `TomcatResources` so that `META-INF/resources` folders in `src/main/resources` no longer fail with a "URI is not hierarchical" exception. Closes gh-13265
1 parent 628cce5 commit 6c7289b

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatResources.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ void addResourceJars(List<URL> resourceJarUrls) {
5959
}
6060
addJar(jar);
6161
}
62+
else if ("jar".equals(url.getProtocol())) {
63+
addJar(url.toString());
64+
}
6265
else {
6366
addDir(new File(url.toURI()).getAbsolutePath(), url);
6467
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2012-2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.context.embedded.tomcat;
18+
19+
import java.net.URL;
20+
import java.util.ArrayList;
21+
import java.util.List;
22+
23+
import org.apache.catalina.Context;
24+
import org.junit.Test;
25+
26+
import static org.mockito.Mockito.mock;
27+
28+
/**
29+
* Tests for {@link TomcatResources}.
30+
*
31+
* @author Phillip Webb
32+
*/
33+
public class TomcatResourcesTests {
34+
35+
@Test
36+
public void nonHierarchicalUri() throws Exception {
37+
// gh-13265
38+
Context context = mock(Context.class);
39+
TomcatResources resources = new TomcatResources.Tomcat8Resources(context);
40+
List<URL> resourceJarUrls = new ArrayList<URL>();
41+
resourceJarUrls.add(new URL("jar:file:/opt/app/app.war!/WEB-INF/classes!/"));
42+
resources.addResourceJars(resourceJarUrls);
43+
}
44+
45+
}

0 commit comments

Comments
 (0)