-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
java.nio.file.FileSystemNotFoundException when creating a resource from a JAR URL #10274
Comments
Does Unlike Jetty 11 (and earlier), where a resource is validated much later, on Jetty 12, a Resource is validated on first reference. A JAR file can be referenced in 2 different ways. As a fileResource jarfile = ResourceFactory.root().newResource(URI.create("file://C:/app/lib/other.jar")); This is As the contents of the jar-fileResourceFactory resourceFactory = ResourceFactory.of(server);
URI jarURI = URI.create("file://C:/app/lib/other.jar");
// Direct manipulation of URI string
Resource jar1 = resourceFactory.newResource(URI.create("jar:" + jarURI.toASCIIString() + "!/"));
// Using newJarResource method
Resource jar2 = resourceFactory.newJarResource(jarURI);
// Using URIUtil technique to adjust URI first
Resource jar3 = resourceFactory.newResource(URIUtil.toJarFileUri(jarURI)); Each of these references result in a |
The way to use a ResourceFactory is to use it via one of the systems that track their reference counts. Tracking resources via a
|
Ahh... It is alive! ResourceFactory.of(loWebAppContext).newResource(loUri) works like a charm. Thanks a lot. This has already cost me countless hours. I was assuming that you must be initializing the filesystems somewhere else. But nice that it is so close. So this can be probaly closed unless you want to improve the error handling |
@ekupcik good to hear. You can use the various Jetty dump methods (see |
Leaving this open, as I'll give an improvement to the Javadoc a whirl. |
First pass at improved javadoc at PR #10276 |
Merged PR #10276 to address documentation concerns |
Jetty version(s)
12
Java version/vendor
(use: java -version)
17
OS type/version
Windows
Description
In my application we are using an embedded jetty that creates multiple web application contexts. The setup is completely custom and consists of collecting multiple JARs in a way so that some of the JARs are shared between the web application contexts while others belong to just one context. For this we are building individual resources using URIs like
jar:file:///C:/app/lib/some.jar!/META-INF/resources
jar:file:///C:/app/lib/other.jar!/META-INF/resources
This worked fine in Jetty 10 but I was not able to get this running when migrating to Jetty 12. There I was trying to build the resources using
ResourceFactory.getBestByScheme(loUri).newResource(loUri)
and but that crashes with a FileSystemNotFoundException. I also tried various other ways/URIs to create a resource for that JAR etc but they just returned null.
After debugging into MountedPathResourceFactory that is returned by ResourceFactory.getBestByScheme(loUri) and the java.nio.file.FileSystems code I think that MountedPathResourceFactory has a bug regarding the FileSystems.
How to reproduce?
The original code crashes with a FileSystemNotFoundException in Paths.get(uri.normalize()). With the hacked workaround the everything is fine. The resource is resource is created and it also the whole web application context works just fine. I am not familiar with the FileSystems API so I have no idea what is the really proper way to use them. But it looks like it is necessary to create them first explicitly before you can use them and I don't think this is something that the application itself should have to do.
The text was updated successfully, but these errors were encountered: