简体   繁体   English

如何将外部库添加到Hadoop映射减少任务

[英]How to add external library to Hadoop map-reduce task

I have MyClass.java to define the map-reduce task. 我有MyClass.java来定义map-reduce任务。 MyClass.java contains the definition of mapper, reducer and main. MyClass.java包含mapper,reducer和main的定义。 It works properly, but if I try to use/add an external jar, I have the message ClassNotFoundException. 它正常工作,但是如果我尝试使用/添加一个外部jar,则会收到消息ClassNotFoundException。

To compile I use the command: 要编译,请使用以下命令:

javac -classpath hadoop_library_path:my_library_path -sourcepath code_path/ -d class_path/ path/MyClass.java

I create the jar, and then I run the task: 我创建了jar,然后运行任务:

hadoop jar maclass.jar MyClass input output -target target

The external jar need to be added also in in "jar hadoop" command? 还需要在“ jar hadoop”命令中添加外部jar吗? I tried with the -libjars option with no result. 我尝试使用-libjars选项,但没有结果。 Any idea? 任何想法?

As I commented, I see two options (there could be more): 正如我所评论的,我看到两个选项(可能还有更多):

  1. Use Eclipse and generate a runnable jar (I am not sure about NetBeans or IntelliJ). 使用Eclipse并生成一个可运行的jar(我不确定NetBeans或IntelliJ)。

  2. Use maven and its shade plugin to generate an uber jar. 使用maven及其阴影插件生成一个超级jar。 You should add all the external libraries that you use as dependencies. 您应该添加所有用作依赖项的外部库。

I recommend the latter option. 我推荐后一种选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM