Description
java.nio.file.spi.FileSystemProvider
loads implementations using ClassLoader.getSystemClassLoader()
.
However, Scala uses a system ClassLoader that doesn't search among JARs on the classpath, resulting in it being impossible to use custom FileSystemProvider
implementations.
As an example, try running the google-cloud-nio
example; here is a gist showing shell cmds and output.
When the same example JAR is run with java -cp …
and scala -cp …
, the former finds the custom FileSystemProvider
(gs
scheme) but the latter doesn't.
I'm currently planning to use this workaround to call FileSystemProvider.loadInstalledProviders
while the system classloader is temporarily overwritten to Thread.currentThread().getContextClassLoader
, which properly finds FileSystemProvider
implementations in user-supplied JARs.
This SO provides basically the same analysis and diagnosis.