Allow new URL(String) with nested JARs

Update JarFile to allow the custom registration of a JAR
`URLStreamHandler` that allows `jar:` URLs to be constructed from
Strings. This removes the previous requirement that all nested JAR URLs
be created with a 'context'.

To supported nested JARs the `java.protocol.handler.pkgs` system
property is changed so that our custom URLHandler is picked for 'jar'
protocols in preference to the Java default.

Fixes gh-269
This commit is contained in:
Phillip Webb
2014-01-25 21:05:06 -08:00
parent c1f8fd2bac
commit 01550fcec6
8 changed files with 176 additions and 76 deletions

View File

@@ -162,25 +162,6 @@ $ java org.springframework.boot.loader.JarLauncher
There are a number of restrictions that you need to consider when working with a Spring
Boot Loader packaged application.
### URLs
URLs for nested jar entries intentionally look and behave like standard jar URLs,
You cannot, however, directly create a nested jar URL from a string:
```
URL url = classLoader.getResoure("/a/b.txt");
String s = url.toString(); // In the form 'jar:file:/file.jar!/nested.jar!/a/b.txt'
new URL(s); // This will fail
```
If you need to obtain URL using a String, ensure that you always provide a context URL
to the constructor. This will ensure that the custom `URLStreamHandler` used to support
nested jars is used.
```
URL url = classLoader.getResoure("/a");
new URL(url, "b.txt");
```
### Zip entry compression
The `ZipEntry` for a nested jar must be saved using the `ZipEntry.STORED` method. This
is required so that we can seek directly to individual content within the nested jar.