【问题标题】:NoSuchMethodError when running on Hadoop but not when run locally在 Hadoop 上运行时出现 NoSuchMethodError 但在本地运行时不会出现
【发布时间】:2023-03-20 21:50:02
【问题描述】:

在 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 版本有问题或任何其他版本冲突。 请有任何想法!

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

【问题讨论】:

  • withFallback 已添加到 Guava 的第 14 版中。看起来当使用java 运行时,您的类路径中有 Guava >= 14,但低于在 Hadoop 中运行时的值。我正在寻找有关 Hadoop 的信息,但我既没有使用过它,也没有使用过 Guava...
  • 你在使用谷歌依赖吗?
  • @Chop 我有番石榴的 v18
  • @JohnSnow 是的,我正在使用 Guava 的依赖项!

标签: java hadoop mapreduce


【解决方案1】:

已编辑:没有看到您的堆栈跟踪。您的堆栈跟踪显示存在版本未匹配。您可以在文档中找到合适的兼容版本。

确保所需的 jar 文件在您的类路径中可用。

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

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

【讨论】:

  • 包括 Guava v18 Jar 在内的所有 JAR 文件都在 Class path 中可用,它使用 JAVA 运行,但它不在 Hadoop 中运行,为什么?
  • 您在哪里看到堆栈跟踪中的版本不匹配?
  • Lcom/google/common/util/concurrent/ListenableFuture;Lcom/google/common/util/concurrent/FutureFallback;Ljava/util/concurrent/Executor;)Lcom/google/common/util/concurrent /ListenableFuture;你的类路径中有这个方法和jar,但是。您的应用程序无法找到它真正需要的东西来完成这项工作..
  • 我也指定了 . (点)在构建 JAR 时作为类路径,但为什么 Hadoop 找不到该方法而 java 找到它?有什么想法吗?
【解决方案2】:

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

如果您碰巧使用的是 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。这是guavaJDK5 反向移植,但它确实可以解决这个问题。

为什么 Google 对一个 非常 旧的 guava 版本(以及一个反向移植)有这种依赖性,我无法理解。

【讨论】:

  • 不是 google-api-client 而是它的 Hadoop 仍然使用 v11,我不知道为什么?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-07-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多