It's possible, although perhaps ill-advised, to read archive formats that are basically renamed .zip files (.ear, .war, .jar, etc.), by using the jar:
URI scheme.
For example, the following code works well when the uri
variable evaluates to a single, top-level archive, e.g. when uri
equals jar:file:///Users/justingarrick/Desktop/test/my_war.war!/
private FileSystem createZipFileSystem(Path path) throws IOException {
URI uri = URI.create("jar:" + path.toUri().toString());
FileSystem fs;
try {
fs = FileSystems.getFileSystem(uri);
} catch (FileSystemNotFoundException e) {
fs = FileSystems.newFileSystem(uri, new HashMap<>());
}
return fs;
}
However, the getFileSystem
and newFileSystem
calls fail with an IllegalArgumentException
when the URI contains nested archives, e.g. when uri
equals jar:jar:file:///Users/justingarrick/Desktop/test/my_war.war!/some_jar.jar!/
(a .jar inside of a .war).
Is there a valid java.net.URI
scheme for nested archive files?
As stated in Jonas Berlin's comment above, the answer is no. From the java.net.JarURLConnection source: