Skip to content
Advertisement

Nested jar: URI

The format of the jar: URI scheme is simply defined to be jar:<url>!/[<entry>].

Is it possible to “nest” two such URIs together and refer to a file inside an archive inside an archive this way? Something like:

jar:jar:http://example.com/!/archive!/file

This should designate /file inside an archive jar:http://example.com/!/archive, that is /archive found in a file provided by http://example.com/. However, URL.openConnection throws an exception:

java.net.MalformedURLException: no !/ in spec

I also cannot replace ! with %21 since that makes the jar: URI invalid, and I am not aware of any escaping that could be performed. Is this somehow possible? Or, as a more generic question, is it possible to store a URI with !/ inside <url> so that it is preserved?

Advertisement

Answer

As it is stated in the source code java.net.JarURLConnection does not handle nested Jar URIs.

Your example jar:jar:http://example.com/!/archive!/fileis parsed as entry archive!/file in the archive jar:http://example.com/. The latter is not a valid jar URI. You can not either escape the !/ sequences, because the text after jar: and before !/ must be a valid URI without any translation.

You can of course provide your own URLConnection implementation that supports nested Jar URIs.

Advertisement