编译hadoop的eclipse插件hadoop-eclipse-plugin-1.2.1.jar 【用来管理hadoop的HDFS和开发MapReduce项目】



文章来源:

http://blog.csdn.net/wind520/article/details/38759149

还可以参考的博客:

编译hadoop1.2.1 eclipse插件: http://www.dataguru.cn/thread-288619-1-1.html


===================================================================================================================

1:下载后hadoop-1.1.2.tar.gz文件,里面包含源代码,并解压到E:\hadoop\hadoop-1.2.1

2:在eclipse导入工程,目录选择:E:\hadoop\hadoop-1.2.1\src\contrib\eclipse-plugin

3:在项目 MapReduceTools 中新建 lib 目录,将 hadoop-1.2.1 下的 hadoop-core-1.2.1.jar,及其 lib 目录下的 commons-cli-1.2.jar、commons-lang-2.4.jar、
commons-configuration-1.6.jar、jackson-mapper-asl-1.8.8.jar、jackson-core-asl-1.8.8.jar、commons-httpclient-3.0.1.jar 拷贝到该目录。


4:修改项目的Libraries


5:修改build-contrib.xml

将E:\hadoop\hadoop-1.2.1\src\contrib目录下的build-contrib.xml文件拷贝到项目目录中,注意:build-contrib.xml文件以eclipse-plugin是在同一级目录中,拷贝完成以后修改build-contrib.xml文件。修改的内容如下。

  1. <property name="name" value="${ant.project.name}"/>  
  2. <property name="root" value="${basedir}"/>  
  3. <property name="version" value="1.2.1"/>  <!--这行为新增的内容-->  
  4. <property name="hadoop.root" location="E:/hadoop/hadoop-1.2.1"/><!--这行为修改的内容-->  
  5. <property name="eclipse.home" location="E:/work/eclipse-jee-kepler-SR2-win32/eclipse" /><!--这行为修改的内容-->  
  <property name="name" value="${ant.project.name}"/>
  <property name="root" value="${basedir}"/>
  <property name="version" value="1.2.1"/>	<!--这行为新增的内容-->
  <property name="hadoop.root" location="E:/hadoop/hadoop-1.2.1"/><!--这行为修改的内容-->
  <property name="eclipse.home" location="E:/work/eclipse-jee-kepler-SR2-win32/eclipse" /><!--这行为修改的内容-->


 这个是前面几行的内容 

6:修改build.xml

如果导入项目的时候选择的是copy的话,需要E:\hadoop\hadoop-1.2.1\src\contrib\eclipse-plugin下的build.xml文件拷贝到项目目录中,不是的话直接修改。

下面是完整的内容:

  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>  
  2.   
  3. <!--  
  4.    Licensed to the Apache Software Foundation (ASF) under one or more  
  5.    contributor license agreements.  See the NOTICE file distributed with  
  6.    this work for additional information regarding copyright ownership.  
  7.    The ASF licenses this file to You under the Apache License, Version 2.0  
  8.    (the "License"); you may not use this file except in compliance with  
  9.    the License.  You may obtain a copy of the License at  
  10.   
  11.        http://www.apache.org/licenses/LICENSE-2.0  
  12.   
  13.    Unless required by applicable law or agreed to in writing, software  
  14.    distributed under the License is distributed on an "AS IS" BASIS,  
  15.    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
  16.    See the License for the specific language governing permissions and  
  17.    limitations under the License.  
  18. -->  
  19.   
  20. <project default="jar" name="eclipse-plugin">  
  21.     <!-- 1.修改 build-contrib.xml的位置,去掉"../" -->  
  22.   <import file="build-contrib.xml"/>  
  23.       
  24.     <!-- 2.添加如下,否则提示"软件包 org.apache.hadoop.fs 不存在" -->  
  25.     <path id="hadoop-jars">  
  26.         <fileset dir="${hadoop.root}/">  
  27.         <include name="hadoop-*.jar"/>  
  28.         </fileset>  
  29.     </path>         
  30.   
  31.   <path id="eclipse-sdk-jars">  
  32.     <fileset dir="${eclipse.home}/plugins/">  
  33.       <include name="org.eclipse.ui*.jar"/>  
  34.       <include name="org.eclipse.jdt*.jar"/>  
  35.       <include name="org.eclipse.core*.jar"/>  
  36.       <include name="org.eclipse.equinox*.jar"/>  
  37.       <include name="org.eclipse.debug*.jar"/>  
  38.       <include name="org.eclipse.osgi*.jar"/>  
  39.       <include name="org.eclipse.swt*.jar"/>  
  40.       <include name="org.eclipse.jface*.jar"/>  
  41.   
  42.       <include name="org.eclipse.team.cvs.ssh2*.jar"/>  
  43.       <include name="com.jcraft.jsch*.jar"/>  
  44.     </fileset>   
  45.   </path>  
  46.   
  47.   <!-- Override classpath to include Eclipse SDK jars -->  
  48.   <path id="classpath">  
  49.     <pathelement location="${build.classes}"/>  
  50.     <pathelement location="${hadoop.root}/build/classes"/>  
  51.     <path refid="eclipse-sdk-jars"/>  
  52.     <path refid="hadoop-jars"/> <!--这行为添加的内容-->  
  53.   </path>  
  54.   
  55.   <!-- Skip building if eclipse.home is unset. -->  
  56.   <target name="check-contrib" unless="eclipse.home">  
  57.     <property name="skip.contrib" value="yes"/>  
  58.     <echo message="eclipse.home unset: skipping eclipse plugin"/>  
  59.   </target>  
  60.   
  61.  <target name="compile" depends="init, ivy-retrieve-common" unless="skip.contrib">  
  62.     <echo message="contrib: ${name}"/>  
  63.     <javac  
  64.      encoding="${build.encoding}"  
  65.      srcdir="${src.dir}"  
  66.      includes="**/*.java"  
  67.      destdir="${build.classes}"  
  68.      debug="${javac.debug}"  
  69.      deprecation="${javac.deprecation}">  
  70.      <classpath refid="classpath"/>  
  71.     </javac>  
  72.   </target>  
  73.   
  74.   <!-- Override jar target to specify manifest -->  
  75.   <target name="jar" depends="compile" unless="skip.contrib">  
  76.     <mkdir dir="${build.dir}/lib"/>  
  77.     <!--这行为添加的内容-->  
  78.     <copy file="${hadoop.root}/hadoop-core-${version}.jar" tofile="${build.dir}/lib/hadoop-core-${version}.jar" verbose="true"/>  
  79.     <!--这行为添加的内容-->  
  80.     <!-- 
  81.     <copy file="${hadoop.root}/build/ivy/lib/Hadoop/common/commons-cli-${commons-cli.version}.jar"  todir="${build.dir}/lib" verbose="true"/> 
  82.      -->  
  83.      <copy file="${hadoop.root}/lib/commons-cli-1.2.jar" todir="${build.dir}/lib" verbose="true"/>  
  84.      <copy file="${hadoop.root}/lib/commons-lang-2.4.jar" todir="${build.dir}/lib" verbose="true"/>  
  85.      <copy file="${hadoop.root}/lib/commons-configuration-1.6.jar" todir="${build.dir}/lib" verbose="true"/>  
  86.      <copy file="${hadoop.root}/lib/jackson-mapper-asl-1.8.8.jar" todir="${build.dir}/lib" verbose="true"/>  
  87.      <copy file="${hadoop.root}/lib/jackson-core-asl-1.8.8.jar" todir="${build.dir}/lib" verbose="true"/>  
  88.      <copy file="${hadoop.root}/lib/commons-httpclient-3.0.1.jar" todir="${build.dir}/lib" verbose="true"/>  
  89.       
  90.     <jar  
  91.       jarfile="${build.dir}/hadoop-${name}-${version}.jar"  
  92.       manifest="${root}/META-INF/MANIFEST.MF">  
  93.       <fileset dir="${build.dir}" includes="classes/ lib/"/>  
  94.       <fileset dir="${root}" includes="resources/ plugin.xml"/>  
  95.     </jar>  
  96.   </target>  
  97.   
  98. </project>  
<?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.
-->

<project default="jar" name="eclipse-plugin">
	<!-- 1.修改 build-contrib.xml的位置,去掉"../" -->
  <import file="build-contrib.xml"/>
	
	<!-- 2.添加如下,否则提示"软件包 org.apache.hadoop.fs 不存在" -->
	<path id="hadoop-jars">
		<fileset dir="${hadoop.root}/">
		<include name="hadoop-*.jar"/>
		</fileset>
	</path>		

  <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"/>
    <path refid="eclipse-sdk-jars"/>
  	<path refid="hadoop-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}">
     <classpath refid="classpath"/>
    </javac>
  </target>

  <!-- Override jar target to specify manifest -->
  <target name="jar" depends="compile" unless="skip.contrib">
    <mkdir dir="${build.dir}/lib"/>
  	<!--这行为添加的内容-->
    <copy file="${hadoop.root}/hadoop-core-${version}.jar" tofile="${build.dir}/lib/hadoop-core-${version}.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}/lib/commons-cli-1.2.jar" todir="${build.dir}/lib" verbose="true"/>
  	 <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>

</project>

7:修改MANIFEST.MF
在Bundle-ClassPath添加下面的内容

  1. Bundle-ClassPath: classes/,  
  2.  lib/hadoop-core.jar,  
  3.  lib/  
Bundle-ClassPath: classes/,
 lib/hadoop-core.jar,
 lib/

8:Ant 编译

a. 右键 MapReduceTools 工程,Properties—>Builders—>New—>Ant Builder
b. 修改New_Builder编辑界面中的内容
Name (见名知意): hadoop_Builder
Buildfile (build.xml的位置): 项目路径下面\build.xml


3. 修改完成保存
4. 点击Project—>Build Project进行生成
点击Project—>Build Project开始进行生成,这时候我们会看到控制台输出一堆相关的编译信息,编译成功会看到在控制台输出 BUILD SUCCESSFUL 。编译结果在 E:\hadoop\hadoop-1.2.1\build\contrib\eclipse-plugin目录下。

  1. Buildfile: E:\work\workspace1\MapReduceTools\build.xml  
  2.   
  3. check-contrib:  
  4.   
  5. init:  
  6.         [echo] contrib: eclipse-plugin  
  7.   
  8. init-contrib:  
  9.   
  10. ivy-download:  
  11.          [get] Getting: http://repo2.maven.org/maven2/org/apache/ivy/ivy/2.1.0/ivy-2.1.0.jar  
  12.          [get] To: E:\hadoop\hadoop-1.2.1\ivy\ivy-2.1.0.jar  
  13.          [get] Not modified - so not downloaded  
  14.   
  15. ivy-probe-antlib:  
  16.   
  17. ivy-init-antlib:  
  18.   
  19. ivy-init:  
  20. [ivy:configure] :: Ivy 2.1.0 - 20090925235825 :: http://ant.apache.org/ivy/ ::  
  21. [ivy:configure] :: loading settings :: file = E:\hadoop\hadoop-1.2.1\ivy\ivysettings.xml  
  22.   
  23. ivy-resolve-common:  
  24.   
  25. ivy-retrieve-common:  
  26. [ivy:cachepath] DEPRECATED: 'ivy.conf.file' is deprecated, use 'ivy.settings.file' instead  
  27. [ivy:cachepath] :: loading settings :: file = E:\hadoop\hadoop-1.2.1\ivy\ivysettings.xml  
  28.   
  29. compile:  
  30.         [echo] contrib: eclipse-plugin  
  31.        [javac] E:\work\workspace1\MapReduceTools\build.xml:69: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds  
  32.   
  33. jar:  
  34. BUILD SUCCESSFUL  
  35. Total time: 1 second  
Buildfile: E:\work\workspace1\MapReduceTools\build.xml

check-contrib:

init:
        [echo] contrib: eclipse-plugin

init-contrib:

ivy-download:
         [get] Getting: http://repo2.maven.org/maven2/org/apache/ivy/ivy/2.1.0/ivy-2.1.0.jar
         [get] To: E:\hadoop\hadoop-1.2.1\ivy\ivy-2.1.0.jar
         [get] Not modified - so not downloaded

ivy-probe-antlib:

ivy-init-antlib:

ivy-init:
[ivy:configure] :: Ivy 2.1.0 - 20090925235825 :: http://ant.apache.org/ivy/ ::
[ivy:configure] :: loading settings :: file = E:\hadoop\hadoop-1.2.1\ivy\ivysettings.xml

ivy-resolve-common:

ivy-retrieve-common:
[ivy:cachepath] DEPRECATED: 'ivy.conf.file' is deprecated, use 'ivy.settings.file' instead
[ivy:cachepath] :: loading settings :: file = E:\hadoop\hadoop-1.2.1\ivy\ivysettings.xml

compile:
        [echo] contrib: eclipse-plugin
       [javac] E:\work\workspace1\MapReduceTools\build.xml:69: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds

jar:
BUILD SUCCESSFUL
Total time: 1 second

安装插件
安装插件到eclipse的话就需要将 hadoop-eclipse-plugin-1.2.1.jar 放入 到eclipse的plugins 目录下,重启 eclipse即可。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值