如何用外部jar运行hadoop?

db2dz4w8  于 2021-06-01  发布在  Hadoop
关注(0)|答案(1)|浏览(411)

我将在hadoop2.9.0上运行map reduce项目。我在我的项目中使用xml rpc包,如下所示:

  1. import org.apache.xmlrpc.*;

我将其他jar放入lib文件夹,当我在hadoop中运行我的项目jar时,它显示以下错误:
错误:java.lang.classnotfoundexception:org.apache.xmlrpc.xmlrpcclient
我执行了这个命令:

  1. 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 ?

bnlyeluc

bnlyeluc1#

私有静态void addjartodistributedcache(class classtoadd,configuration conf)引发ioexception{

  1. // Retrieve jar file for class2Add
  2. String jar = classToAdd.getProtectionDomain().
  3. getCodeSource().getLocation().
  4. getPath();
  5. File jarFile = new File(jar);
  6. // Declare new HDFS location
  7. Path hdfsJar = new Path("/user/hadoopi/lib/"
  8. + jarFile.getName());
  9. // Mount HDFS
  10. FileSystem hdfs = FileSystem.get(conf);
  11. // Copy (override) jar file to HDFS
  12. hdfs.copyFromLocalFile(false, true,
  13. new Path(jar), hdfsJar);
  14. // Add jar to distributed classPath
  15. DistributedCache.addFileToClassPath(hdfsJar, conf);

}

展开查看全部

相关问题