跳到正文
W Winse Blog
bigdata 1 min read

Ant实现hadoop插件Run-on-Hadoop

撇开eclipse的插件不说,如果直接在eclipse运行main方法,运行的时刻会提示map,reduce找不到的错误。其实就是没有把需要类的包提供给集群环境。

看过使用hadoop-eclipse-plugin插件(http://winseclone.iteye.com/blog/1837035)最后解析的Run-on-Hadoop的实现,不难得出下面的方法步骤:

  • 首先打包jar,
  • 然后把jar的路径给Main的-Dmapred.jar参数。

这样,就可以把环境需要的class上传到hadoop了。

主要的ant代码如下:

	<property name="exported.jar" value="${build.dir}/tmp-runonhadoop-${now}.jar"></property>

	<target name="jar" depends="build" description="Make tmp-run.jar">
		<jar jarfile="${exported.jar}" basedir="${build.classes}">
			<fileset dir="${build.classes}" includes="**/example/*" />
			<exclude name="**/core-site.xml"/>
		</jar>
	</target>

	<target name="WordCount" depends="build, jar" >
		<java classname="com.winse.hadoop.examples.WordCount" failonerror="true" fork="yes">
			<arg line="-fs=${fs.default.name} -jt=${mapred.job.tracker} -Dmapred.jar=${exported.jar} /test/input /test/output"/>

			<classpath refid="runon.classpath"/>
		</java>
	</target>

# 源码

其实就build.xml重要,其他就是exmaples里面的wordcount的源码而已。 其实build.xml也不重要,重要的思路!思路清晰了做事情就八九不离十了!


【原文地址】

–END

在 GitHub 上讨论

欢迎通过 GitHub Issue 留言或反馈。每条讨论都会关联到对应文章的源文件路径。

2013-03-28-run-on-hadoop-on-ant.md

Related posts