轉自: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安裝
ANT安裝
Eclipse安裝
Hadoop安裝
插件配置
- 編譯插件過程需要使用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編譯會報錯),編輯後如下
- # 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/
- eclipse.home=D:\eclipse
- 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可以自己定義新的路徑)
- <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>
好了,差不多了。此時運行會報錯,原因是這個文件中還需要拷貝兩個文件到插件包中,和上面道理一樣,由於我們沒編譯整個項目,所以需要修改,直接引用包中內容。
然後查詢target name="jar",修改該標籤內的內容(好多教程中,說最後執行 ant jar,實際上就是直接執行這部分,如果不加jar ,則執行project 標籤 default 指向的target ,還好默認就是jar target) ,註釋兩個copy,新增兩個copy,可以看到需要了兩個jar,一個是hadoop-core-${version}.jar ,另一個是commons-cli-${commons-cli.version}.jar 。這兩個包最後會自動打入到插件包中,可以從官網下載的文件中或自己編譯的文件看到結果
- <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>
恩,該有的都有了,啓動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下方
集成成功!