java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument

2022-09-01 06:09:01

我正在尝试在我的本地运行这个grpc-Java示例。相同的相应原型文件在这里。当我尝试在本地运行时,它会从这里引发以下异常:

Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V
    at io.grpc.ServiceDescriptor.validateMethodNames(ServiceDescriptor.java:129)
    at io.grpc.ServiceDescriptor.<init>(ServiceDescriptor.java:83)
    at io.grpc.ServiceDescriptor.<init>(ServiceDescriptor.java:51)
    at io.grpc.ServiceDescriptor$Builder.build(ServiceDescriptor.java:219)
    at io.grpc.examples.helloworld.GreeterGrpc.getServiceDescriptor(GreeterGrpc.java:251)
    at io.grpc.examples.helloworld.GreeterGrpc$GreeterImplBase.bindService(GreeterGrpc.java:84)
    at io.grpc.internal.AbstractServerImplBuilder.addService(AbstractServerImplBuilder.java:125)
    at io.grpc.internal.AbstractServerImplBuilder.addService(AbstractServerImplBuilder.java:63)
    at com.cw.predictive.HelloWorldServer.start(HelloWorldServer.java:56)
    at com.cw.predictive.HelloWorldServer.main(HelloWorldServer.java:92)

这是我的pom.xml,如这里所提到的:

 <dependencies>
         <dependency>
          <groupId>io.grpc</groupId>
          <artifactId>grpc-netty</artifactId>
          <version>1.1.2</version>
        </dependency>

      <dependency>
        <groupId>io.grpc</groupId>
        <artifactId>grpc-protobuf</artifactId>
        <version>1.1.2</version>
      </dependency>

      <dependency>
        <groupId>io.grpc</groupId>
        <artifactId>grpc-stub</artifactId>
        <version>1.1.2</version>
      </dependency>
  </dependencies>

答案 1
**Please add following dependencies in your project.**
<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>23.6-jre</version>
</dependency> 
<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpcore</artifactId>
    <version>4.4.8</version>
</dependency>

答案 2

对于在EMR上遇到此错误的任何其他人。为了将s3a地址系统用于S3文件,我需要S3aFileSystem Jar,它似乎在EMR 6.7,Hadoop 3.2.1集群上不可用 - 否则我会收到错误。为了解决这个问题,我在 spark-submit 参数中包含了这个问题。然后我开始在OP的问题中注意到错误。降级到3.2.0修复了这个问题,但后来我遇到了另一个错误; .我通过升级到3.2.2来解决这个问题:。然后,我能够使用EMR 6.7读取和写入S3a地址Class org.apache.hadoop.fs.s3a.S3AFileSystem not found--packages org.apache.hadoop:hadoop-aws:3.2.1NoSuchMethodError: SemaphoredDelegatingExecutor while writing files to S3--packages org.apache.hadoop:hadoop-aws:3.2.2


推荐