您好,登錄后才能下訂單哦!
目錄說明
在編譯之前,我們需要先下載后hadoop 1.2.1的源碼文件,并解壓到合適的位置。目錄結構如下:
Eclipse: D:\eclipse
Hadoop: D:\hadoop-1.2.1
Step1導入 Hadoop-eclipse 插件工程
1. 下載hadoop-1.2.1.tar.gz,并解壓縮到 D盤根目錄下
2. 在 Eclipse 中選擇 File—>Import—>General/Existing Projectsinto Workspace 導入Hadoop的Eclipse插件項目。選擇路徑為D:\hadoop-1.2.1\src\contrib\eclipse-plugin,然后點擊Finish.其默認的項目名稱是 MapReduceTools。(最好將該文件提取出來導入)
Step2導入所需 jar 包
在項目 MapReduceTools 中新建 lib 目錄,將 hadoop-1.2.1 下的 hadoop-core-1.2.1.jar(重命名為 hadoop-core.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拷貝到該目錄。
Step3修改build-contrib.xml
將D:\hadoop-1.2.1\src\contrib目錄下的build-contrib.xml文件拷貝到項目目錄中,注意:build-contrib.xml文件拷貝到當前項目的一級目錄中,拷貝完成以后修改build-contrib.xml文件。修改的內容如下。
<!-- 修改 hadoop 存放目錄 -->
<property name="hadoop.root"location="D:/hadoop-1.2.1"/>
<!-- 添加 eclipse 存放目錄 -->
<property name="eclipse.home"location="D:/eclipse" />
<!-- 添加 hadoop 版本 -->
<property name="version"value="1.2.1"/>
Step4修改build.xml
<?xmlversion="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 informationregarding copyright ownership.
The ASF licenses this file to You under theApache License, Version 2.0
(the "License"); you may not usethis 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 agreedto in writing, software
distributed under the License is distributedon an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANYKIND, either express or implied.
See the License for the specific languagegoverning permissions and
limitations under the License.
-->
<projectdefault="jar" name="eclipse-plugin">
<!-- 1.修改 build-contrib.xml的位置,去掉"../" -->
<importfile="build-contrib.xml"/>
<!-- 2.添加如下,否則提示"軟件包 org.apache.hadoop.fs 不存在" -->
<path id="hadoop-jars">
<fileset dir="${hadoop.root}/">
<includename="hadoop-*.jar"/>
</fileset>
</path>
<path id="eclipse-sdk-jars">
<filesetdir="${eclipse.home}/plugins/">
<includename="org.eclipse.ui*.jar"/>
<includename="org.eclipse.jdt*.jar"/>
<includename="org.eclipse.core*.jar"/>
<includename="org.eclipse.equinox*.jar"/>
<includename="org.eclipse.debug*.jar"/>
<includename="org.eclipse.osgi*.jar"/>
<includename="org.eclipse.swt*.jar"/>
<include name="org.eclipse.jface*.jar"/>
<includename="org.eclipse.team.cvs.ssh3*.jar"/>
<includename="com.jcraft.jsch*.jar"/>
</fileset>
</path>
<!-- Override classpath to include EclipseSDK jars -->
<path id="classpath">
<pathelement location="${build.classes}"/>
<pathelementlocation="${hadoop.root}/build/classes"/>
<pathrefid="eclipse-sdk-jars"/>
<pathrefid="hadoop-jars"/> <!--這行為添加的內容-->
</path>
<!-- Skip building if eclipse.home isunset. -->
<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 specifymanifest -->
<target name="jar"depends="compile" unless="skip.contrib">
<mkdirdir="${build.dir}/lib"/>
<!--這行為添加的內容-->
<copyfile="${hadoop.root}/hadoop-core-${version}.jar"tofile="${build.dir}/lib/hadoop-core-${version}.jar"verbose="true"/>
<!--這行為添加的內容-->
<!--
<copyfile="${hadoop.root}/build/ivy/lib/Hadoop/common/commons-cli-${commons-cli.version}.jar" todir="${build.dir}/lib"verbose="true"/>
-->
<copyfile="${hadoop.root}/lib/commons-cli-1.2.jar"todir="${build.dir}/lib" verbose="true"/>
<copyfile="${hadoop.root}/lib/commons-lang-2.4.jar"todir="${build.dir}/lib" verbose="true"/>
<copyfile="${hadoop.root}/lib/commons-configuration-1.6.jar"todir="${build.dir}/lib" verbose="true"/>
<copyfile="${hadoop.root}/lib/jackson-mapper-asl-1.8.8.jar"todir="${build.dir}/lib" verbose="true"/>
<copyfile="${hadoop.root}/lib/jackson-core-asl-1.8.8.jar"todir="${build.dir}/lib" verbose="true"/>
<copyfile="${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>
Step5修改MANIFEST.MF
在Bundle-ClassPath添加下面的內容。
Bundle-ClassPath: classes/,
lib/hadoop-core.jar,
lib/commons-cli-1.2.jar,
lib/commons-httpclient-3.0.1.jar,
lib/jackson-core-asl-1.8.8.jar,
lib/jackson-mapper-asl-1.8.8.jar,
lib/commons-configuration-1.6.jar,
lib/commons-lang-2.4.jar
Step6Ant 編譯1.右鍵 MapReduceTools 工程,Properties—>Builders—>New—>Ant Builder
2. 修改New_Builder編輯界面中的內容
Name (見名知意): plugin_Builder
Buildfile (build.xml的位置):D:\hadoop-1.2.1\src\contrib\eclipse-plugin\build.xml
3. 修改完成保存
4. 點擊Project—>Build Project進行生成
點擊Project—>Build Project開始進行生成,這時候我們會看到控制臺輸出一堆相關的編譯信息,編譯成功會看到在控制臺輸出 BUILD SUCCESSFUL 。編譯結果在d:\hadoop-1.2.1\build\contrib\eclipse-plugin 目錄下。
Step6查看編譯成果
編譯結果在 d:\hadoop-1.2.1\build\contrib\eclipse-plugin 目錄下。我們可以看到在目錄下生成了hadoop-eclipse-plugin-1.2.1.jar,這時如果我們需要安裝插件到eclipse的話就需要將hadoop-eclipse-plugin-1.2.1.jar 放入 到eclipse的plugins 目錄下,重啟 eclipse即可。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。