When trying to test using “mvn test” the test fail with error:
java.nio.file.ProviderNotFoundException: Provider “jar” not found.
Compiling the app and running works without issues.
It is this piece of code, that for some reason fails, when testing:
final FileSystem zipfs = FileSystems.newFileSystem(jarPath, Collections.emptyMap());
I use openjdk-11 and this import to get the zip library into the code:
import java.nio.file.FileSystems;
I have tried various settings in pom.xml and setting the classpath, but nothing has worked so far. Ie.:
<artifactId>maven-surefire-plugin</artifactId> <version>2.22.1</version> <configuration> <systemPropertyVariables> <java.io.tmpdir>${project.build.directory}</java.io.tmpdir> </systemPropertyVariables> <jvm>${env.JAVA_HOME}/bin/java</jvm> <javaCommandLineOptions> <option> <key>--add-modules</key> <value>jdk.zipfs</value> </option> </javaCommandLineOptions> </configuration>
Running –list modules, I can see jdk.zipfs@11.0.14.1
I have a feeling, that it is the test plugin, that for some reason do not pick up the zip library.
What am I missing to get the test to work?
Advertisement
Answer
I found the culprit to be the error message being misleading. When using mvn test, the environment looks different from the compiled version and jarPath was pointing at a directory and not a file. I wish, that the error message would have been more informative about not being able to open the location instead of not being able to find the provider “jar”