在Hadoop 2.0.0-cdh4.3.1上运行程序时,MapReduce给出了以下错误:
java.lang.NoSuchMethodError:com.google.common.util.concurrent.Futures.withFallback
但是当我通过执行JAR:
进行测试时java -cp myclass
运行完美。我不知道这里,如果所谓的期货。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版本错误或任何其他版本冲突。有什么想法吗?
编辑:我已经证实在Guava v18 JAR中没有"withFallback"方法。
已编辑:没有看到您的堆栈跟踪。您的堆栈跟踪显示有一个版本不匹配。您可以在这些文档中找到合适的兼容版本。
确保所需的jar文件在您的类路径中可用。
当您使用-cp选项运行时,您的JVM在所有目录位置搜索所需的jar文件,以;
确保你还添加了;.;在类路径中,这会导致JVM加载/搜索当前工作目录中可用的类/jar文件。
我相信我已经找到了问题所在(或者至少为我找到了解决方案)。
如果你碰巧使用谷歌的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
。这是guava
的JDK5
后端口,但它确实可以解决这个问题。
为什么Google对一个非常旧的guava版本有这种依赖(尽管如此,还是一个后端口),我不明白。