网上讲的用Ant编译eclipse hadoop plugin插件,都讲的很复杂,对于我这样的菜鸟哪里经得起这么多折腾,本人经过实践,写出我的编译经验
首先安装eclipse,记住eclipse版本一定要3.3+,笔者就犯过这样的错误,我开始用3.2版本编译总是提示jar包找不到,纠结了很久,最后去官网看了说明才明白,所一建议大家多看官方文档。,本次编译环境如下:
ubuntu12
ant 1.9.1
eclipse 3.6
hadoop 1.1.2
首先请预先安装ant并设置环境变量,下载hadoop-1.1.2.tar.gz源码解压
修改${hadoop.root}/src/contrib目录的build-contrib.xml文件,添加eclipse路径和hadoop版本信息
<property name="eclipse.home" location="/usr/local/eclipse3.6" /> <property name="version" value="1.1.2"/>
修改${hadoop.root}/src/contrib/eclipse-plugin目录下的build.xml文件,在id为classpath的path节点添加hadoop-core的jar依赖
<!-- Override classpath to include Eclipse SDK jars --> <path id="classpath"> <pathelement location="${build.classes}"/> <pathelement location="${hadoop.root}/build/classes"/> <!--hadoop-core --> <pathelement location="${hadoop.root}/hadoop-core-1.1.2.jar"/> <path refid="eclipse-sdk-jars"/> </path>
找到name为jar的target,将相应的jar文件打包进插件的lib目录
<!-- Override jar target to specify manifest --> <target name="jar" depends="compile" unless="skip.contrib"> <mkdir dir="${build.dir}/lib"/> <!--<copy file="${hadoop.root}/build/hadoop-core-${version}.jar" tofile="${build.dir}/lib/hadoop-core.jar" verbose="true"/> <copy file="${hadoop.root}/build/ivy/lib/Hadoop/common/commons-cli-${commons-cli.version}.jar" todir="${build.dir}/lib" verbose="true"/>--> <copy file="${hadoop.root}/hadoop-core-${version}.jar" tofile="${build.dir}/lib/hadoop-core.jar" verbose="true"/> <copy file="${hadoop.root}/lib/commons-cli-${commons-cli.version}.jar" todir="${build.dir}/lib" verbose="true"/> <!-- 将以下jar包打进hadoop-eclipse-1.1.2.jar中 --> <copy file="${hadoop.root}/lib/commons-lang-2.4.jar" todir="${build.dir}/lib" verbose="true"/> <copy file="${hadoop.root}/lib/commons-configuration-1.6.jar" todir="${build.dir}/lib" verbose="true"/> <copy file="${hadoop.root}/lib/jackson-mapper-asl-1.8.8.jar" todir="${build.dir}/lib" verbose="true"/> <copy file="${hadoop.root}/lib/jackson-core-asl-1.8.8.jar" todir="${build.dir}/lib" verbose="true"/> <copy file="${hadoop.root}/lib/commons-httpclient-3.0.1.jar" todir="${build.dir}/lib" verbose="true"/> <jar jarfile="${build.dir}/hadoop-${name}-${version}.jar" manifest="${root}/META-INF/MANIFEST.MF"> <fileset dir="${build.dir}" includes="classes/ lib/"/> <fileset dir="${root}" includes="resources/ plugin.xml"/> </jar> </target>
修改MANIFEST.MF文件里面Bundle-ClassPath属性值
Bundle-ClassPath: classes/,lib/hadoop-core.jar,lib/commons-cli-1.2.jar,lib/commons-configuration-1.6.jar,lib/commons-httpclient-3.0.1.jar,lib/commons-lang-2.4.jar,lib/jackson-core-asl-1.8.8.jar,lib/jackson-mapper-asl-1.8.8.jar
在命令行进入 ${hadoop.root}/src/contrib/eclipse-plugin目录,输入: ant jar
最后在${hadoop.root}/build/contrib/eclipse-plugin目录生成打包好的插件,将hadoop-eclipse-plugin-1.1.2.jar文件复制到eclipse的plugins目录即可
eclipse3.6下载地址:http://archive.eclipse.org/eclipse/downloads/drops/R-3.6-201006080911/
ant 1.9.1 下载地址:http://download.youkuaiyun.com/detail/yonghutwo/5664701
插件下载地址: http://download.youkuaiyun.com/detail/yonghutwo/5657241