Hadoop在Eclipse中的插件编译

Hadoop自0.20.x版本后不再提供现成的hadoop-eclipse插件而是给出了源码自行编译。
 
一、Hadoop运行环境
 
1、Ubuntu 12.04.1
 
2、eclipse-4.2.2
 
3、hadoop-1.1.2
 
二、工具安装
 
1、ant-1.9
 
http://ant.apache.org/bindownload.cgi下载apache-ant-1.9.0-bin.tar.gz
 
将压缩包解压
 
sudo tar –zxf apache-ant-1.9.0-bin.tar.gz
 
然后将解压后的文件夹路径添加到/etc/profile的PATH中
 
2、automake autoconflibtool

安装命令 sudo apt-get install automake autoconf libtool
 
三、构建hadoop
 
1、编辑{HADOOP_HOME}/build.xml
 
(1)、hadoop版本做修改
 
<propertyname="version"value="1.1.3-SNAPSHOT"/>  大概30行
 
修改为:
 
<propertyname="version"value="1.1.3"/>
 
(2)、ivy下载进行注释,因为已经包含了ivy.jar
 
 <!--targetname="ivy-download"description="To downloadivy"unless="offline">大概2000多行处
 
 <get src="${ivy_repo_url}"dest="${ivy.jar}"usetimestamp="true"/>
 
 </target-->
 
(3)、去除对ivy-download的依赖关系,保留如下:
 
 <targetname="ivy-init-antlib"depends="ivy-init-dirs,ivy-probe-antlib"  离上面注释不远的下方
 
2、编辑{HADOOP_HOME}/src/contrib./build-contrib.xml
 
添加两行,补充Eclipse路径和Hadoop版本
 
<projectname="hadoopbuildcontrib"xmlns:ivy="antlib:org.apache.ivy.ant">
 
<propertyname="eclipse.home"location="eclipse的安装目录"/>//添加
 
<propertyname="version"value="1.1.3"/>  //添加
 
<propertyname="name"value="${ant.project.name}"/>
 
<propertyname="root"value="${basedir}"/>
 
<propertyname="hadoop.root"location="${root}/../../../"/>
 
...
 
</project>
 
3、构建hadoop
 
$  cd ${HADOOP-HOME}
 
$  antcompile
 
四、构建eclipse插件
 
1、修改${HADOOP_HOME}/src/contrib/eclipse-plugin/build.xml
 
加入几行copy地址,指定添加的jar包:
 
<!-- Override jar target to specifymanifest -->
 
<target name="jar"depends="compile" unless="skip.contrib">
 
<mkdirdir="${build.dir}/lib"/>
 
 
 
  <copyfile="${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"/>
 
  <copyfile="${hadoop.root}/lib/commons-configuration-1.6.jar"tofile="${build.dir}/lib/commons-configuration-1.6.jar"verbose="true"/>
 
  <copyfile="${hadoop.root}/lib/commons-httpclient-3.0.1.jar"tofile="${build.dir}/lib/commons-httpclient-3.0.1.jar"verbose="true"/>
 
  <copy file="${hadoop.root}/lib/commons-lang-2.4.jar"tofile="${build.dir}/lib/commons-lang-2.4.jar"verbose="true"/>
 
  <copy file="${hadoop.root}/lib/jackson-core-asl-1.8.8.jar"tofile="${build.dir}/lib/jackson-core-asl-1.8.8.jar"verbose="true"/>
 
  <copyfile="${hadoop.root}/lib/jackson-mapper-asl-1.8.8.jar"tofile="${build.dir}/lib/jackson-mapper-asl-1.8.8.jar" 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>
 
2、修改${HADOOP_HOME}/src/contrib/eclipse-plugin/META-INF/MENIFEST.MF,指定CLASS_PATH
 
Bundle-ClassPath: classes/,
 
lib/hadoop-core.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,lib/commons-cli-1.2.jar
 
3、构建插件
 
cd${HADOOP_HOME}/usr/contrib/eclipse-plugin
 
ant jar
 
输出的eclipse插件地址为:${HADOOP_HOME}/build/contrib/eclipse-plugin/hadoop-eclipse-plugin-1.1.2.jar

相关推荐