nosuchmethoderror,但在本地运行时发生错误

e4eetjau  于 2021-05-29  发布在  Hadoop
关注(0)|答案(2)|浏览(292)

在hadoop 2.0.0-cdh4.3.1 mapreduce上运行程序时,出现以下错误:

java.lang.NoSuchMethodError:com.google.common.util.concurrent.Futures.withFallback

但是当我通过执行jar进行测试时:

java -cp myclass

它运行完美。我不知道这里好像所谓的futures.withfallback存在于jar中,这就是为什么它在本地执行的原因。它使用Guava连接Cassandra,完整堆栈跟踪如下:

attempt_201507081740_21115_m_000050_0: [FATAL] Child - Error running child : java.lang.NoSuchMethodError: com.google.common.util.concurrent.Futures.withFallback(Lcom/google/common/util/concurrent/ListenableFuture;Lcom/google/common/util/concurrent/FutureFallback;Ljava/util/concurrent/Executor;)Lcom/google/common/util/concurrent/ListenableFuture;
attempt_201507081740_21115_m_000050_0:  at com.datastax.driver.core.Connection.initAsync(Connection.java:176)
attempt_201507081740_21115_m_000050_0:  at com.datastax.driver.core.Connection$Factory.open(Connection.java:721)
attempt_201507081740_21115_m_000050_0:  at com.datastax.driver.core.ControlConnection.tryConnect(ControlConnection.java:244)
attempt_201507081740_21115_m_000050_0:  at com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:190)
attempt_201507081740_21115_m_000050_0:  at com.datastax.driver.core.ControlConnection.connect(ControlConnection.java:78)
attempt_201507081740_21115_m_000050_0:  at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1272)
attempt_201507081740_21115_m_000050_0:  at com.datastax.driver.core.Cluster.init(Cluster.java:158)
attempt_201507081740_21115_m_000050_0:  at com.datastax.driver.core.Cluster.connect(Cluster.java:248)
attempt_201507081740_21115_m_000050_0:  at com.datastax.driver.core.Cluster.connect(Cluster.java:281)
attempt_201507081740_21115_m_000050_0:  at com.cassandra.CassandraHandler.getConnection(CassandraHandler.java:40)
attempt_201507081740_21115_m_000050_0:  at com.json.flatten.DynamicJsonFlattener.<init>(DynamicJsonFlattener.java:35)
attempt_201507081740_21115_m_000050_0:  at com.mapreduce.Map.map(Map.java:18)
attempt_201507081740_21115_m_000050_0:  at com.mapreduce.Map.map(Map.java:13)
attempt_201507081740_21115_m_000050_0:  at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:140)
attempt_201507081740_21115_m_000050_0:  at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:672)
attempt_201507081740_21115_m_000050_0:  at org.apache.hadoop.mapred.MapTask.run(MapTask.java:330)
attempt_201507081740_21115_m_000050_0:  at org.apache.hadoop.mapred.Child$4.run(Child.java:268)
attempt_201507081740_21115_m_000050_0:  at java.security.AccessController.doPrivileged(Native Method)
attempt_201507081740_21115_m_000050_0:  at javax.security.auth.Subject.doAs(Subject.java:396)
 attempt_201507081740_21115_m_000050_0:  at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1408)
attempt_201507081740_21115_m_000050_0:  at org.apache.hadoop.mapred.Child.main(Child.java:262)

hadoop版本或任何其他版本有问题。有什么想法吗!
编辑:我已经验证了guavav18 jar中没有“withfallback”方法。现在我不知所措,有什么想法请帮我!

mxg2im7a

mxg2im7a1#

编辑:没有看到你的stacktrace。你的stacktrace显示有一个版本不匹配。您可以在这些文档中找到合适的兼容版本。
确保所需的jar文件在类路径中可用。
当您使用-cp选项运行时,jvm会在所有目录位置中搜索所需的jar文件,这些目录位置之间用;在类路径变量中给定。
确保您还添加了;。;在classes路径中,这会导致jvm加载/搜索当前工作目录中可用的class/jar文件。

p1iqtdky

p1iqtdky2#

我相信我已经找到了问题所在(或者至少为我找到了解决办法)。
如果你碰巧使用谷歌的 google-api-client 图书馆: com.google.api-client » google-api-client 它依赖于 guava-jdk5 13.0 . 此版本的 guava-jdk5 没有 Futures.withFallback (这是在 14.0 )可能与你对Guava的依赖性相冲突。
如果这是您的情况,那么解决方案是向 com.google.guava:guava-jdk5:17.0 . 它是一个 JDK5 后端口 guava ,但它确实能解决这个问题。
我不明白为什么谷歌会依赖一个非常古老的guava版本(尽管有一个后台端口)。

相关问题