1

我想按照SDK Javadoc包 README中的描述使用 NIO 从 Google Cloud Storage 读取文件。我想我错过了一些关于FileSystemProvider在 Maven 配置中触发安装新的东西。

我创建了一个尽可能简单的项目来演示. 亮点如下。

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>

应用程序.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"));
  }
}

输出:

$ 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]
4

0 回答 0