(三)hadoop學習:eclipse的hadoop插件製作

轉自:http://blog.csdn.net/reaper1022/article/details/11009797


環境

WIN7 64bit

Eclipse for Java EE 64bit內核版本 4.3.0 246M  http://mirrors.neusoft.edu.cn/eclipse/technology/epp/downloads/release/kepler/R/eclipse-jee-kepler-R-win32-x86_64.zip

Hadoop 1.2.1 下載源碼完整版本,下載時注意文件名字和大小60.8M https://issues.apache.org/jira/secure/attachment/12425381/hadoop-0.20.1-eclipse-plugin.jar

JDK 1.7.0_25-b17 http://download.oracle.com/otn-pub/java/jdk/7u25-b17/jdk-7u25-windows-x64.exe

ANT 1.9.2 http://apache.fayea.com/apache-mirror//ant/binaries/apache-ant-1.9.2-bin.zip


JDK安裝

.exe格式,一路下一步,注意修改安裝路徑C:\Java
安裝後,我的電腦右鍵屬性-》高級系統設置-》高級-》Path 中加入 ;C:\Java\jdk1.7.0_25\bin 注意前面的半角分號

ANT安裝

解壓至D盤根目錄,注意解壓後路徑格式如下:D:\apache-ant-1.9.2
加入環境變量 ;D:\apache-ant-1.9.1\bin

Eclipse安裝

解壓至D盤根目錄 E:\eclipse

Hadoop安裝

解壓至D盤根目錄D:\hadoop-1.2.1

插件配置

官方文檔位置:http://wiki.apache.org/hadoop/EclipsePlugIn
注意:在官方文檔位置下有兩個鏈接 JIRA MAPREDUCE-1262   JIRA MAPREDUCE-1280
這兩個鏈接是官方提供好的Eclipse插件包,可以直接下載下來放置在E:\eclipse\plugins 目錄下,重啓Eclipse 後,可見

官方文字中提供了幾點需要注意的地方
  • 編譯插件過程需要使用hadoop類文件
  • 編譯前需要在D:\hadoop-1.2.1\src\contrib\eclipse-plugin\build.properties中設置eclipse.home變量
  • 執行編譯需要確認一個Hadoop版本信息

1.修改D:\hadoop-1.2.1\src\contrib\eclipse-plugin\build.properties 文件

加入eclipse.home和版本信息(版本變量名再未加入時ant編譯會報錯),編輯後如下

[plain] view plaincopy
  1. #   Licensed under the Apache License, Version 2.0 (the "License");  
  2. #   you may not use this file except in compliance with the License.  
  3. #   You may obtain a copy of the License at  
  4. #  
  5. #       http://www.apache.org/licenses/LICENSE-2.0  
  6. #  
  7. #   Unless required by applicable law or agreed to in writing, software  
  8. #   distributed under the License is distributed on an "AS IS" BASIS,  
  9. #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
  10. #   See the License for the specific language governing permissions and  
  11. #   limitations under the License.  
  12.   
  13.   
  14. output.. = bin/  
  15. bin.includes = META-INF/,\  
  16.                plugin.xml,\  
  17.                resources/,\  
  18.                classes/,\  
  19.                classes/,\  
  20.                lib/  
  21. eclipse.home=D:\eclipse  
  22. version=1.2.1  


2.修改D:\hadoop-1.2.1\src\contrib\eclipse-plugin\build.xml文件,需要在文件中加入Hadoop類路徑(按理說,這個不應該添加,在build文件中指向的類路徑爲build目錄,當然前提是已經編譯過Hadoop的源碼,成功在./build目錄中生成類文件,我們並沒有編譯源碼,好吧直接飲用下載包中的內容)

找到文件中eclipse-sdk-jars標籤,修改成如下內容(第二個fileset就是新增的內容,可能複製代碼有問題,注意一下。當然如果您熟悉ANT可以自己定義新的路徑)

[plain] view plaincopy
  1.  <path id="eclipse-sdk-jars">  
  2.    <fileset dir="${eclipse.home}/plugins/">  
  3.      <include name="org.eclipse.ui*.jar"/>  
  4.      <include name="org.eclipse.jdt*.jar"/>  
  5.      <include name="org.eclipse.core*.jar"/>  
  6.      <include name="org.eclipse.equinox*.jar"/>  
  7.      <include name="org.eclipse.debug*.jar"/>  
  8.      <include name="org.eclipse.osgi*.jar"/>  
  9.      <include name="org.eclipse.swt*.jar"/>  
  10.      <include name="org.eclipse.jface*.jar"/>  
  11.   
  12.      <include name="org.eclipse.team.cvs.ssh2*.jar"/>  
  13.      <include name="com.jcraft.jsch*.jar"/>  
  14.    </fileset>  
  15. <!--build need hadoop classes file.-->  
  16. <fileset dir="../../../">  
  17.     <include name="hadoop*.jar"/>  
  18. </fileset>  
  19.  </path>  

好了,差不多了。此時運行會報錯,原因是這個文件中還需要拷貝兩個文件到插件包中,和上面道理一樣,由於我們沒編譯整個項目,所以需要修改,直接引用包中內容。


然後查詢target name="jar",修改該標籤內的內容(好多教程中,說最後執行 ant jar,實際上就是直接執行這部分,如果不加jar ,則執行project 標籤 default 指向的target ,還好默認就是jar target) ,註釋兩個copy,新增兩個copy,可以看到需要了兩個jar,一個是hadoop-core-${version}.jar ,另一個是commons-cli-${commons-cli.version}.jar 。這兩個包最後會自動打入到插件包中,可以從官網下載的文件中或自己編譯的文件看到結果


[plain] view plaincopy
  1. <target name="jar" depends="compile" unless="skip.contrib">  
  2.     <mkdir dir="${build.dir}/lib"/>  
  3.     <!--  
  4.     <copy file="${hadoop.root}/build/hadoop-core-${version}.jar" tofile="${build.dir}/lib/hadoop-core.jar" verbose="true"/>  
  5.     <copy file="${hadoop.root}/build/ivy/lib/Hadoop/common/commons-cli-${commons-cli.version}.jar"  todir="${build.dir}/lib" verbose="true"/>  
  6.     -->  
  7.      <copy file="${hadoop.root}/hadoop-core-${version}.jar" tofile="${build.dir}/lib/hadoop-core.jar" verbose="true"/>  
  8.     <copy file="${hadoop.root}/lib/commons-cli-${commons-cli.version}.jar"  todir="${build.dir}/lib" verbose="true"/>  
  9.   
  10.     <jar  
  11.       jarfile="${build.dir}/hadoop-${name}-${version}.jar"  
  12.       manifest="${root}/META-INF/MANIFEST.MF">  
  13.       <fileset dir="${build.dir}" includes="classes/ lib/"/>  
  14.       <fileset dir="${root}" includes="resources/ plugin.xml"/>  
  15.     </jar>  
  16.   </target>  

恩,該有的都有了,啓動cmd 

切換目錄至D:\hadoop-1.2.1\src\contrib\eclipse-plugin

輸入 ant 然後回車,最後提示

BUILD SUCCESSFUL
Total time: 5 seconds

成功!


WIN+E 資源管理器,進入目錄 D:\hadoop-1.2.1\build\contrib\eclipse-plugin ,看到文件 hadoop-eclipse-plugin-1.2.1.jar ,恩,我們自己的插件出來了


拷貝 hadoop-eclipse-plugin-1.2.1.jar 文件至 D:\eclipse\plugins 目錄,確認安裝吧


確認安裝

啓動Eclipse 後 Window->Open Perspective->Other ,彈出對話框列表中,會出現圖標爲藍色大象,文字爲Map/Reduce ,就在JPA下方


集成成功!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章