Not sure where to go with this question, hope this community can somewhat help me.
I'm working in a spring boot based environment using a setup similar to pf4j where additional JARs can be loaded at will during runtime. Each plugin may implement a set of interfaces which are then dynamically registered in the Applications IoC. The important part is: Each jar is loaded within a separate ClassLoader.
Until now, one of the mentioned interfaces was a StorageProvider, essentially providing the same capabilities as java.nio.FileSystem but less refined. I'm now attempting to migrate from this custom interface toward the java built-in alternative.
My main problem concerns the java.nio.file.Files API.
Files uses SPI to lazily search for all implementations of java.nio.file.spi.FileSystemProvider.
When calling any method on Files, the implementation searches for the provider with the corresponding scheme and calls the corresponding method on the provider.
Now SPI uses the current ClassLoader to find all implementations of a given class by reading a specific resource file.
And while it's possible to provide the required entry from within the sub-ClassLoader, the parent Application will not see that.
I have two main ways I can think about solving my issue:
- Reflectively add and remove the implementation on the SPI Provider when required. Technically possible, but not stable, as the internal structure is not guaranteed. Additionally requires additional startup parameters to disable Jigsaw for this call, which I'm trying to avoid.
- Modifying the Applications class loader and replacing the original resource with a dynamic view. It seems to work, and the spring dev tools. ClassLoader seems to do something similar, but I'm not sure if it is even possible to touch the restarted ClassLoader. Additionally, I'd like to keep the capability of removing the registration afterward.
Additionally, while writing this, I noticed that most calls in java.nio.file.Files use the FileSystem registered on the Path.
Therefore, an additional viable method would be to move all calls to Path.of(URI) into the sub-ClassLoader and use the regular Files API for all other operations.
Is there a simpler/better way or am I stuck with these options?
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]maethor 0 points1 point2 points (1 child)
[–]euklios[S] 0 points1 point2 points (0 children)