在Hadoop上运行时出现NoSuchMethodError,但在本地运行时却没有

时间:2015-07-24 06:42:57

标签: java hadoop mapreduce

在Hadoop 2.0.0-cdh4.3.1上运行程序时MapReduce给出了以下错误:

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

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

java -cp myclass

它运行完美。我不在这里,好像在JAR中出现了所谓的 Futures.withFallback 这就是为什么它在本地被执行了。它使用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版本或任何其他版本冲突有问题。 请任何想法!

编辑:我已经确认Guava v18 JAR中没有“withFallback”方法。现在我一无所知,请帮助我任何想法!

2 个答案:

答案 0 :(得分:1)

编辑:没看到你的堆栈跟踪。你的stacktrace显示有一个版本未匹配。你可以在那里找到适当的兼容版本。

确保您的类路径中有所需的jar文件。

当您使用-cp选项运行时,您的jvm会在所有目录位置中搜索所需的jar文件;在你的classpath变量中给出。

确保您还添加了;。;在您的类路径中,这会导致jvm加载/搜索当前工作目录中可用的类/ jar文件。

答案 1 :(得分:0)

我相信我已经找到了问题(或者至少是我的解决方案)。

如果您正好使用Google的google-api-client库:

com.google.api-client » google-api-client

它依赖于guava-jdk5 13.0。此版本的guava-jdk5没有 Futures.withFallback (在14.0中引入)并且可能与您对番石榴的依赖性相冲突。

如果是这种情况,解决方案是向com.google.guava:guava-jdk5:17.0添加依赖项。它是JDK5 guava的后端,但它可以解决此问题。

为什么Google对非常旧的番石榴版本(以及后端版本)的依赖性超出了我的范围。