-
Notifications
You must be signed in to change notification settings - Fork 40.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Special case for root of classpath resource in archive
This turns out to affect JPA, but only because it looks for a URL for the root of the classpath using ClassLoader.getResource("") which barfs in an app launched from an executable JAR. It's easy to make a special case for "" in the class loader, so I went ahead and did that. Possibly need to think what the implication of getResources("") is as well (not tested in an app yet). Fixes gh-420
- Loading branch information
Dave Syer
committed
Mar 6, 2014
1 parent
afac085
commit 8168e8a
Showing
4 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...oot-loader/src/test/java/org/springframework/boot/loader/LaunchedURLClassLoaderTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2012-2013 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot.loader; | ||
|
||
import java.net.URL; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* @author Dave Syer | ||
*/ | ||
public class LaunchedURLClassLoaderTests { | ||
|
||
@Test | ||
public void resolveResourceFromArchive() throws Exception { | ||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(new URL[] { new URL( | ||
"jar:file:src/test/resources/jars/app.jar!/") }, getClass() | ||
.getClassLoader()); | ||
assertNotNull(loader.getResource("demo/Application.java")); | ||
} | ||
|
||
@Test | ||
public void resolveResourcesFromArchive() throws Exception { | ||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(new URL[] { new URL( | ||
"jar:file:src/test/resources/jars/app.jar!/") }, getClass() | ||
.getClassLoader()); | ||
assertTrue(loader.getResources("demo/Application.java").hasMoreElements()); | ||
} | ||
|
||
@Test | ||
public void resolveRootPathFromArchive() throws Exception { | ||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(new URL[] { new URL( | ||
"jar:file:src/test/resources/jars/app.jar!/") }, getClass() | ||
.getClassLoader()); | ||
assertNotNull(loader.getResource("")); | ||
} | ||
|
||
@Test | ||
public void resolveRootResourcesFromArchive() throws Exception { | ||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(new URL[] { new URL( | ||
"jar:file:src/test/resources/jars/app.jar!/") }, getClass() | ||
.getClassLoader()); | ||
assertTrue(loader.getResources("").hasMoreElements()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters