zoukankan      html  css  js  c++  java
  • 使用hadoop eclipse plugin提交Job并添加多个第三方jar

    来自:http://heipark.iteye.com/blog/1171923

    通过 "conf.set("tmpjars", jars);" 可以设置第三方jar,之前一直只是添加一个jar,运行OK,今天打算添加多个jar的时候发现mapreduce在运行时找不到 class(ClassNotFoundException),跟踪代码发现jar文件的确上传到了HDFS中,所以甚是无解,后来上传jar到 hdfs,然后使用DistributedCache.addFileToClassPath()方法也不行。郁闷半天,后来看到job.xml中有一段 奇怪的设置,mapred.job.classpath.files的value为"/user/heipark/lib/commons-lang- 2.3.jar;/user /heipark/lib/guava-r08.jar",可以看到这个分隔符是分号(我的OS是windows),在linux系统和hadoop系统 一般都是逗号和冒号分隔,然后我继续挖,发现DistributedCache.addArchiveToClassPath()方法(tmpjars也 会用这个方法)中使用了“System.getProperty("path.separator")”,于是灵感闪现,修改该值为linux系统的冒 号,我嚓,居然成功了,搞了我4个小时,eclipse终于可以添加多个第三方jar包了。封装了方法,在main方法直接添加jar包就可以了。

    调用:

    addTmpJar("D:/Java/new_java_workspace/scm/lib/guava-r08.jar", conf);

    方法定义:

        /**
         * 为Mapreduce添加第三方jar包
         *
         * @param jarPath
         *            举例:D:/Java/new_java_workspace/scm/lib/guava-r08.jar
         * @param conf
         * @throws IOException
         */
        public static void addTmpJar(String jarPath, Configuration conf) throws IOException {
            System.setProperty("path.separator", ":");
            FileSystem fs = FileSystem.getLocal(conf);
            String newJarPath = new Path(jarPath).makeQualified(fs).toString();
            String tmpjars = conf.get("tmpjars");
            if (tmpjars == null || tmpjars.length() == 0) {
                conf.set("tmpjars", newJarPath);
            } else {
                conf.set("tmpjars", tmpjars + "," + newJarPath);
            }
        }

  • 相关阅读:
    Java-运算符
    Java-类型转化
    Java-数组
    Java-循环结构(for,while)
    Java-选择结构(if-else)
    Java-数据类型(引用类型)
    HDFS JournalNode 故障
    Grok patterns 汇总
    HBase 查询导致RegionServer OOM故障复盘
    【翻译】Spark 调优 (Tuning Spark) 中文版
  • 原文地址:https://www.cnblogs.com/sunxucool/p/3899470.html
Copyright © 2011-2022 走看看