cryptomator / cryptofs

Java Filesystem Provider with integrated encryption
GNU Affero General Public License v3.0
94 stars 35 forks source link

ProviderNotFoundException in example #6

Closed xgp closed 7 years ago

xgp commented 7 years ago

I created a simple example to try out cryptofs, but it is unable to load the provider:

Caused by: java.nio.file.ProviderNotFoundException: Provider "cryptomator" not found
    at java.nio.file.FileSystems.newFileSystem(FileSystems.java:341)
    at java.nio.file.FileSystems.newFileSystem(FileSystems.java:276)
    at Test.main(Test.java:18)

Here is my pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.github.xgp</groupId>
  <artifactId>cryptofstest</artifactId>
  <packaging>jar</packaging>
  <version>0.1-SNAPSHOT</version>
  <name>cryptofstest</name>
  <url>http://maven.apache.org</url>

  <parent>
    <groupId>com.github.xgp</groupId>
    <artifactId>oss-parent</artifactId>
    <version>0.1</version>
  </parent>

  <properties>
    <java.version>1.8</java.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.cryptomator</groupId>
      <artifactId>cryptofs</artifactId>
      <version>1.0.1</version>
    </dependency>
  </dependencies>

</project>

And my src/main/java/Test.java:

import org.cryptomator.cryptofs.*;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Stream;

public class Test {
    public static void main(String[] args) throws Exception {

    Path storageLocation = Paths.get("/tmp", "cryptofs");
    if (!Files.exists(storageLocation)) Files.createDirectories(storageLocation);

    URI uri2 = CryptoFileSystemUris.createUri(storageLocation);
    try (FileSystem fileSystem = FileSystems
         .newFileSystem(uri2,
                CryptoFileSystemProperties.cryptoFileSystemProperties()
                .withPassphrase("password")
                .build())) {

        // obtain a path to a test file
        Path testFile = fileSystem.getPath("/foo/bar/test");

        if (!Files.exists(testFile)) {
        // create all parent directories
        Files.createDirectories(testFile.getParent());

        // Write data to the file
        Files.write(testFile, "test".getBytes());
        }

        // List all files present in a directory
        try (Stream<Path> listing = Files.list(testFile.getParent())) {
        listing.forEach(System.out::println);
        }
    }

    }
}

And I run it with:

mvn clean compile exec:java -Dexec.mainClass="Test"

Any ideas? Am I missing something obvious?

overheadhunter commented 7 years ago

Is it possible, that META-INF/services/java.nio.file.spi.FileSystemProvider is missing for some reason?

xgp commented 7 years ago

This appears to be a deficiency of running via the mvn exec:java command, as it works fine via plain old java .... Maybe it's a classloading problem with the exec plugin. Anyway, I'm closing it as it doesn't seem like an issue with cryptofs, but the exec plugin.