【问题标题】:NoSuchMethodError while reading from google cloud storage from Dataproc using java使用java从Dataproc从谷歌云存储读取时出现NoSuchMethodError
【发布时间】:2017-09-11 00:56:44
【问题描述】:

这是我读取云存储文件的方法

public static String getStringObject(String bucketName, String fileName) throws Exception{
        BlobId blobId = BlobId.of(bucketName, fileName);
        byte[] content = storage.readAllBytes(blobId);
        String contentString = new String(content, UTF_8);
        return contentString;
    }

当我从我的开发环境中调用此方法以从存储桶中读取文件时,它工作正常。但是,当我在运行 spark 作业时从 Dataproc 集群调用此方法时,会引发以下错误。

Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor;
    at com.google.api.gax.retrying.BasicRetryingFuture.<init>(BasicRetryingFuture.java:77)
    at com.google.api.gax.retrying.DirectRetryingExecutor.createFuture(DirectRetryingExecutor.java:75)
    at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:53)
    at com.google.cloud.storage.StorageImpl.readAllBytes(StorageImpl.java:460)`

这是我的 maven pom.xml 的一部分

<dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>google-cloud-storage</artifactId>
            <version>1.4.0</version>
        </dependency>
        <dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>19.0</version>
</dependency>
<dependency>
    <groupId>com.google.api-client</groupId>
    <artifactId>google-api-client</artifactId>
    <version>1.22.0</version>
</dependency>

我在这里做错了什么?

【问题讨论】:

    标签: java google-cloud-storage google-api-client nosuchmethoderror google-cloud-dataproc


    【解决方案1】:

    在 Dataproc 上运行时,您通常会在客户端应用程序类路径中找到 Hadoop 库。这允许与 HDFS 和 GCS 交互,但也意味着存在 Hadoop 版本的番石榴。

    您可以在 SO answer 中找到使用阴影解决此问题的方法

    【讨论】:

    • 感谢您的帮助。我不得不将多个包添加到重定位列表中。终于开始工作了。
    • @GolakSarangi 你能告诉我你添加了哪些包。我也面临同样的问题
    猜你喜欢
    • 2023-03-30
    • 2021-02-24
    • 1970-01-01
    • 2021-07-30
    • 1970-01-01
    • 1970-01-01
    • 2023-01-30
    • 2017-05-06
    • 1970-01-01
    相关资源
    最近更新 更多