【问题标题】:Google Cloud Storage Runtime Error谷歌云存储运行时错误
【发布时间】:2017-08-26 09:33:29
【问题描述】:

我只是想使用以下代码从我的 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 存储:

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

我尝试了各种&lt;exclusions&gt;,但似乎无法成功。 谢谢 蒂姆

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>

【问题讨论】:

  • 你能分享完整的 POM 文件吗?也许还有其他原因(例如阴影)导致问题。
  • 在原始帖子中添加了完整的 POM 文件。看到什么了吗?

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


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    尝试删除&lt;enableJarClasses&gt;false&lt;/enableJarClasses&gt;。我怀疑这会导致 GCS 库的 JAR 未包含在 GAE 上运行的工件中。因此,可能缺少必需的类。

    【讨论】:

    • 谢谢,但它似乎没有任何区别。我应该为其他依赖项添加例外吗?
    猜你喜欢
    • 2017-02-10
    • 2020-06-01
    • 2018-07-22
    • 1970-01-01
    • 2020-09-10
    • 1970-01-01
    • 2017-08-20
    • 2012-10-15
    • 2016-10-12
    相关资源
    最近更新 更多