0

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?

Jacob
  • 11
  • 3

1 Answers1

1

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"

Jacob
  • 11
  • 3
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 06 '22 at 13:07
  • I agree that the error message is misleading. In my case I encountered this error when the file already existed, but was empty. – Dennie Sep 28 '22 at 13:08