hadoop1.2.1 eclipse plugin ant build

linux安装
1.下载hadoop1.2.1
http://mirror.esocc.com/apache/hadoop/common/hadoop-1.2.1/hadoop-1.2.1.tar.gz

2.解压hadoop1.2.1( 注意:我hadoop-1.2.1的安装根目录为/soft/hadoop-1.2.1,安装路径不同下面注意修改)
tar -zxvf hadoop-1.2.1.tar.gz

3.jdk安装配置(略过)
注意:最好使用jdk1.6

4.安装eclipse(略过)
注意:eclipse3.6.1(Centos 6.4自带eclipse),eclipse3.7编译会出错,笔者已经试过

5.导入eclipse-plugin项目
导入/soft/hadoop-1.2.1/src/contrib/eclipse-plugin项目

6.导入项目需要的jar


7.配置build.properties,增加eclipse.home和version,可以复制,替换build.properties
#   Licensed 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.


output.. = bin/
bin.includes = META-INF/,\
               plugin.xml,\
               resources/,\
               classes/,\
               classes/,\
               lib/

#add eclipse.home and hadoop version
eclipse.home=/usr/lib/eclipse
version=1.2.1


8.修改build.xml
a.搜索<path id="eclipse-sdk-jars">,在这个path里加入编译时hadoop需要的jar,可以直接复制替换原来的eclipse-sdk-jars的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>
 
     <!-- 增加 -->
     <!--build need hadoop classes file.-->
     <fileset dir="../../../">
         <include name="hadoop*.jar"/>
      </fileset>
	  </path>
         


b.搜索<target name="jar" depends="compile" unless="skip.contrib">,将2个copy标签注释,可以复制直接替换原来的compile的target
<!-- 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
      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>


9.ant编译
a.在eclipse中点击Window->Show View->Other->Ant->Ant
b.将build.xml用鼠标拖到Ant视图
c.点Ant视图的绿色run图标
如图:



10.编译完成

猜你喜欢

转载自joe-zhjiang.iteye.com/blog/1978657
今日推荐