java - Google 云存储运行时错误

标签 java maven google-app-engine google-cloud-storage

我只是尝试使用以下代码从我的 GAE (java) 列出 Google Cloud Storage 存储桶的内容:

GcsService gcsService = GcsServiceFactory.createGcsService(new RetryParams.Builder()
                        .initialRetryDelayMillis(10)
                        .retryMaxAttempts(10)
                        .totalRetryPeriodMillis(15000)
                        .build());

try{
     ListResult list = gcsService.list("MyTestBucket", new ListOptions.Builder().setPrefix("testFolder").setRecursive(true).build());
   }

它可以编译,但是当我运行它时,我收到以下我不明白的错误:

Caused by: java.lang.NoSuchMethodError: com.google.appengine.tools.cloudstorage.GcsService.list(Ljava/lang/String;Lcom/google/appengine/tools/cloudstorage/ListOptions;)Lcom/google/appengine/tools/cloudstorage/ListResult;

POM 依赖项如下所示,包含 Google Storage:

<dependency>
    <groupId>com.google.appengine.tools</groupId>
    <artifactId>appengine-gcs-client</artifactId>
    <version>0.6</version>
</dependency>

我尝试过各种<exclusions>但似乎无法使其发挥作用。 谢谢 蒂姆

POM 文件:

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
<version>1.0</version>

<groupId>com.xyz.abc</groupId>
<artifactId>xyzclienttest</artifactId>

<properties>
    <appengine.app.version>1</appengine.app.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<prerequisites>
    <maven>3.1.0</maven>
</prerequisites>

<dependencies>
    <!-- Compile/runtime dependencies -->
    <dependency>
        <groupId>com.google.appengine</groupId>
        <artifactId>appengine-api-1.0-sdk</artifactId>
        <version>1.9.54</version>
    </dependency>

    <dependency>
        <groupId>com.google.appengine.tools</groupId>
        <artifactId>appengine-gcs-client</artifactId>
        <version>0.6</version>
    </dependency>

    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet-core</artifactId>
        <version>2.17</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-moxy</artifactId>
        <version>2.17</version>
    </dependency>
    <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</artifactId>
        <version>1.10</version>
    </dependency>
    <dependency>
        <groupId>com.googlecode.objectify</groupId>
        <artifactId>objectify</artifactId>
        <version>5.1.5</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
        <version>1</version>
    </dependency>
    <dependency>
        <groupId>javax.jdo</groupId>
        <artifactId>jdo-api</artifactId>
        <version>3.1</version>
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.3.1</version>
    </dependency>
    <dependency>
        <groupId>com.github.mpkorstanje</groupId>
        <artifactId>simmetrics-core</artifactId>
        <version>3.2.3</version>
    </dependency>

</dependencies>

<build>      <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>versions-maven-plugin</artifactId>
            <version>2.1</version>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>display-dependency-updates</goal>
                        <goal>display-plugin-updates</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <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>
                <encoding>UTF-8</encoding>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.6</version>
        </plugin>
        <plugin>
            <groupId>com.google.appengine</groupId>
            <artifactId>appengine-maven-plugin</artifactId>
            <version>1.9.54</version>
            <configuration>
                <enableJarClasses>false</enableJarClasses>
                <!-- Comment in the below snippet to bind to all IPs instead of just localhost -->
                <!-- address>0.0.0.0</address>
                <port>8080</port -->
                <!-- Comment in the below snippet to enable local debugging with a remove debugger
                     like those included with Eclipse or IntelliJ -->
                <!-- jvmFlags>
                  <jvmFlag>-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n</jvmFlag>
                </jvmFlags -->
            </configuration>
        </plugin>
    </plugins>
</build>

<reporting>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>findbugs-maven-plugin</artifactId>
            <configuration>
                <!--
                    Enables analysis which takes more memory but finds more bugs.
                    If you run out of memory, changes the value of the effort element
                    to 'low'.
                -->
                <effort>Max</effort>
                <!-- Reports all bugs (other values are medium and max) -->
                <threshold>Low</threshold>
                <onlyAnalyze>com.xyz.abc.*,com.xyz.abc.util.*</onlyAnalyze>
                <!-- Produces XML report -->
                <xmlOutput>true</xmlOutput>
                <xmlOutputDirectory>target/site</xmlOutputDirectory>
            </configuration>
        </plugin>       
    </plugins>
</reporting>

最佳答案

修好了!我查看了 .war 文件,发现有两个版本的 appengine-gcs-client jar 文件。 0.2 和 0.6。我做了一个 mvn clean 并解决了问题。我真的应该以前就这么做了:-(活到老学到老!

关于java - Google 云存储运行时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45893982/

相关文章:

java - toString方法中可以使用void吗

Java 将字符串拆分为 Double[ ]

java - Eclipse + Tomcat + Maven 即使在添加 Maven 库后也找不到类异常

maven - 在 CodeBuild maven 作业上使用适当的 ECS 凭据

python - 使用 Google App Engine 时需要解决哪些安全问题?

python - Google Speech API 无法在 Google 存储 : error 404 上找到文件

java - 如何从复合 JAR 加载资源?

java - 如何转换 moxy json 输出?

java - 使用 Thymeleaf 作为模板的 Spring Boot 发送电子邮件 - 配置不起作用

google-app-engine - SSL 谷歌应用引擎