Linux下编译Hadoop的Eclipse插件

【广告位】文章头部(标题下方、正文上方)

虽然使用Java编写MapReduce作业有点繁琐,但是对于刚入门Hadoop的新手来说,有利于理解hadoop的一些底层实现,这无疑也是一种巨大的收获。目前大部分的MapReduce作业都是使用Hive,Pig完成的,当然也有用其他语言实现的,通过使用HadoopStreaming的方式,用原生Java写MR作业的只有很少一部分。在Hadoop2.x中,已经不支持eclipse的插件了,不过可以在配置的XML文件里,加入远程监控的端口,来监控hadoop集群。

由于1.0之后hadoop已经不自带eclipse的插件包了,所以得需要我们自己编译源码生成插件包,建议在Linux下编译,Windows下可能有时候会报一些莫名其妙的错误,先介绍下散仙的环境,CentOS6.4的版本,hadoop1.2.0的版本,

hadoop的目录在/root/hadoop-1.2.0下面

eclipse的目录在/root/eclipse下面

总结一下如下的四步来完成编译eclipse插件的过程

步骤 操作
1 进入/root/hadoop-1.2.0/src/contrib/eclipse-plugin下面,修改build.xml
2 进入/root/hadoop-1.2.0/src/contrib下面,修改build-contrib.xml
3 /root/hadoop-1.2.0/src/contrib/eclipse-plugin/META-INF下面,修改MANIFEST.MF文件
4 使用shell命令进入/root/hadoop-1.2.0/src/contrib/eclipse-plugin下面,执行ant命令进行构建


下面散仙就来详细介绍下,每一步具体怎么操作,在第一步里我们需要向build.xml里面,加入的内容有
1,eclipse的根目录.
2.hadoop的版本号.
3.hadoop的一些引用包.
4,在javac里加入  includeantruntime="on".
内容如下所示:

  <!-- 1,2步的配置  -->
  <property name="eclipse.home" location="/root/eclipse"/>
  <property name="version" value="1.2.0"/>
  <!--第3步的配置  -->
  <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"  tofile="${build.dir}/lib/commons-cli.jar" verbose="true"/>
<copy file="${hadoop.root}/lib/commons-configuration-1.6.jar"  tofile="${build.dir}/lib/commons-configuration.jar" verbose="true"/>
<copy file="${hadoop.root}/lib/commons-httpclient-3.0.1.jar"  tofile="${build.dir}/lib/commons-httpclient.jar" verbose="true"/>
<copy file="${hadoop.root}/lib/commons-lang-2.4.jar"  tofile="${build.dir}/lib/commons-lang.jar" verbose="true"/>
<copy file="${hadoop.root}/lib/jackson-core-asl-1.8.8.jar"  tofile="${build.dir}/lib/jackson-core-asl.jar" verbose="true"/>
<copy file="${hadoop.root}/lib/jackson-mapper-asl-1.8.8.jar"  tofile="${build.dir}/lib/jackson-mapper-asl.jar" verbose="true"/>
 <!--第4步的配置  -->
 includeantruntime="on">

更多详情见请继续阅读下一页的精彩内容: http://www.linuxidc.com/Linux/2013-11/92528p2.htm

相关阅读:

Ubuntu 13.04上搭建Hadoop环境 http://www.linuxidc.com/Linux/2013-06/86106.htm

Ubuntu上搭建Hadoop环境(单机模式+伪分布模式) http://www.linuxidc.com/Linux/2013-01/77681.htm

Ubuntu下Hadoop环境的配置 http://www.linuxidc.com/Linux/2012-11/74539.htm

单机版搭建Hadoop环境图文教程详解 http://www.linuxidc.com/Linux/2012-02/53927.htm

搭建Hadoop环境(在Winodws环境下用虚拟机虚拟两个Ubuntu系统进行搭建) http://www.linuxidc.com/Linux/2011-12/48894.htm

下文贴出整个XML,现在我们看第二大步的配置,修改build-contrib.xml,内容如下:

 <!--  原始的为off -->
<property name="javac.deprecation" value="on"/>

第三步的修改MANIFEST.MF内容如下:

Bundle-ClassPath: classes/,lib/commons-cli.jar,lib/commons-httpclient.jar,lib/Hadoop-core.jar,lib/jackson-mapper-asl.jar,lib/commons-configuration.jar,lib/commons-lang.jar,lib/jackson-core-asl.jar

第四步执行命令:截图如下: 


 
最后,插件类生成的目录,截图如下: 


 
下面散仙给出所有配置的全部信息,以供参考,下图的是build.xml里面的内容

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->

            <!-- build.xml -->
<project default="jar" name="eclipse-plugin">

  <import file="../build-contrib.xml"/>

 
  <property name="eclipse.home" location="/root/eclipse"/>
  <property name="version" value="1.2.0"/>
 
  <path id="eclipse-sdk-jars">
    <fileset dir="${eclipse.home}/plugins/">
      <include name="org.eclipse.ui*.jar"/>
      <include name="org.eclipse.jdt*.jar"/>
      <include name="org.eclipse.core*.jar"/>
      <include name="org.eclipse.equinox*.jar"/>
      <include name="org.eclipse.debug*.jar"/>
      <include name="org.eclipse.osgi*.jar"/>
      <include name="org.eclipse.swt*.jar"/>
      <include name="org.eclipse.jface*.jar"/>

      <include name="org.eclipse.team.cvs.ssh2*.jar"/>
      <include name="com.jcraft.jsch*.jar"/>
    </fileset>
  </path>

  <!-- Override classpath to include Eclipse SDK jars -->
  <path id="classpath">
    <pathelement location="${build.classes}"/>
    <pathelement location="${hadoop.root}/build/classes"/>
  <fileset dir="${hadoop.root}">
        <include name="**/*.jar" />
    </fileset>
    <path refid="eclipse-sdk-jars"/>
  </path>

  <!-- Skip building if eclipse.home is unset. -->
  <target name="check-contrib" unless="eclipse.home">
    <property name="skip.contrib" value="yes"/>
    <echo message="eclipse.home unset: skipping eclipse plugin"/>
  </target>

【广告位】文章正文中间

 <target name="compile" depends="init, ivy-retrieve-common" unless="skip.contrib">
    <echo message="contrib: ${name}"/>
    <javac
    encoding="${build.encoding}"
    srcdir="${src.dir}"
    includes="**/*.java"
    destdir="${build.classes}"
    debug="${javac.debug}"
    deprecation="${javac.deprecation}"
  includeantruntime="on">
    <classpath refid="classpath"/>
    </javac>
  </target>

本文已展示 50% · 完整内容需验证码解锁

关注公众号,解锁完整文章

微信扫码关注 星哥玩云, 在公众号对话框回复关键词 星哥玩云博客 获取验证码。输入后即可阅读全文, 一次解锁全站文章通用。

星哥玩云 微信公众号二维码
微信扫一扫 / 长按识别,关注「星哥玩云」
【广告位】文章底部(正文结束、评论区上方)
评论功能已在静态化后停用 · 返回顶部 ↑