你好,游客 登录 注册 搜索
背景:
阅读新闻

Hadoop的classloader和libjars配置

[日期:2012-07-11] 来源:Linux社区  作者:slixf [字体:大 中 小]

这些清楚了,在解析libjars这个参数时,会将指定的jar全部放到conf文件的tmpjars参数中,然后加载到classloader中。这意味着,也可以在config文件中指定tmpjars来设置项目依赖的jar文件。
再看看getLibJars这方法:

public static URL[] getLibJars(Configuration conf) throws IOException {
    String jars = conf.get("tmpjars");
    if(jars==null) {
      return null;
    }
    String[] files = jars.split(",");
    URL[] cp = new URL[files.length];
    for (int i=0;i<cp.length;i++) {
      Path tmp = new Path(files[i]);
      cp[i] = FileSystem.getLocal(conf).pathToFile(tmp).toURI().toURL();
    }
    return cp;
  }

用红色标记的字体表示,这个libjar文件需要放在文件系统中,不能是hdfs,也不能是s3n/s3或者其他的系统,必须是Hadoop所在的windows或者Linux的文件系统。否则你会得到这个错误:

Exception in thread "main" java.lang.IllegalArgumentException: This file system object (file:///) does not support access to the request path 's3n://userprofile/lib/mahout.jar' You possibly called FileSystem.get(conf) when you should have called FileSystem.get(uri, conf) to obtain a file system supporting your path. at org.apache.hadoop.fs.FileSystem.checkPath(FileSystem.java:351) at org.apache.hadoop.fs.RawLocalFileSystem.pathToFile(RawLocalFileSystem.java:47) at org.apache.hadoop.fs.LocalFileSystem.pathToFile(LocalFileSystem.java:49) at org.apache.hadoop.util.GenericOptionsParser.getLibJars(GenericOptionsParser.java:309) at org.apache.hadoop.util.GenericOptionsParser.processGeneralOptions(GenericOptionsParser.java:263) at org.apache.hadoop.util.GenericOptionsParser.parseGeneralOptions(GenericOptionsParser.java:387) at org.apache.hadoop.util.GenericOptionsParser.<init>(GenericOptionsParser.java:154) at org.apache.hadoop.util.GenericOptionsParser.<init>(GenericOptionsParser.java:139) at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:59) 

此外在看看这两行加载jar的代码:

conf.setClassLoader(new URLClassLoader(libjars, conf.getClassLoader()));
 Thread.currentThread().setContextClassLoader(...)

这意味这,这些包都被加载到当前classloader的子loader中,不是当前classloader中,所以,你不能在当前的job中直接使用这些包。

linux
相关资讯       hadoop开发 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款