"gs" scheme missing from installed FileSystemProviders

601 views Asked by At

I want to read a file from Google Cloud Storage using NIO as described in the SDK Javadoc and the package README. I think I'm missing something about triggering the installation of a new FileSystemProvider in the Maven configuration.

I created a simple-as-possible project to demonstrate. The highlights follow.

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.example</groupId>
  <artifactId>gcs-nio</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.5.1</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <name>playground</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <!-- https://mvnrepository.com/artifact/com.google.cloud/google-cloud-nio -->
    <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>google-cloud-nio</artifactId>
      <version>0.22.0-alpha</version>
    </dependency>
  </dependencies>
</project>

App.java:

public class App {

  public static void main(String[] args) {
    System.out.println("FileSystemProvider schemes:");
    List<FileSystemProvider> fileSystemProviders = FileSystemProvider.installedProviders();
    for (FileSystemProvider provider : fileSystemProviders) {
      System.out.println(provider.getScheme());
    }

    // This fails; I want it to succeed.
    Paths.get(URI.create("gs://dataflow-samples/shakespeare/kinglear.txt"));
  }
}

Output:

$ mvn compile -q exec:java -Dexec.mainClass=com.example.App 
FileSystemProvider schemes:
file
jar
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java (default-cli) on project gcs-nio: An exception occured while executing the Java class. Provider "gs" not installed -> [Help 1]
0

There are 0 answers