【问题标题】:how to run hadoop with external jar?如何使用外部 jar 运行 hadoop?
【发布时间】:2018-11-03 06:12:36
【问题描述】:

我将在 Hadoop 2.9.0 上运行我的 map reduce 项目。我在我的项目中使用 xml-rpc 包如下:

import org.apache.xmlrpc.*;    

我将其他 jar 放入 lib 文件夹,当我在 Hadoop 中运行我的项目 jar 时,它显示此错误:

错误:java.lang.ClassNotFoundException:org.apache.xmlrpc.XmlRpcClient

我执行了这个命令:

bin/hadoop jar MRV.jar SumMR /user/hadoop/input /user/hadoop/output -libjars lib/xmlrpc-2.0.1.jar: lib/commons-codec-1.10.jar

如何在不出现ClassNotFoundException错误的情况下执行此命令?

【问题讨论】:

  • 查看如何使用 Maven/Gradle 对 JAR 文件进行着色
  • 反正我觉得应该在运行时引入jars路径。
  • 当然,着色是最简单的方法,因此您无需管理一堆不同的罐子

标签: java hadoop jar


【解决方案1】:

私有静态无效 addJarToDistributedCache (类classToAdd,配置conf) 抛出 IOException {

// Retrieve jar file for class2Add
String jar = classToAdd.getProtectionDomain().
        getCodeSource().getLocation().
        getPath();
File jarFile = new File(jar);

// Declare new HDFS location
Path hdfsJar = new Path("/user/hadoopi/lib/"
        + jarFile.getName());

// Mount HDFS
FileSystem hdfs = FileSystem.get(conf);

// Copy (override) jar file to HDFS
hdfs.copyFromLocalFile(false, true,
    new Path(jar), hdfsJar);

// Add jar to distributed classPath
DistributedCache.addFileToClassPath(hdfsJar, conf);

}

【讨论】:

  • 感谢您的回复。您代码中的String jar 是我的.classes 的路径。我添加了库,想知道它的路径。
猜你喜欢
  • 1970-01-01
  • 2017-01-30
  • 2015-08-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多