关于Hadoop 编译 Eclipse 插件的过程,自己操作了一次,感觉里面还是有些小点需要说明一下的
环境
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版本信息
好的,按照注意点先编辑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
接下来需要在文件中加入Hadoop类路径(按理说,这个不应该添加,在build文件中指向的类路径为build目录,当然前提是已经编译过Hadoop的源码,成功在./build目录中生成类文件,我们并没有编译源码,好吧直接饮用下载包中的内容)
不会ANT没关系,随便找个路径标签加进去,找到文件中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>
好了,差不多了。此时运行会报错,原因是这个文件中还需要拷贝两个文件到插件包中,和上面道理一样,由于我们没编译整个项目,所以需要修改,直接引用包中内容。
修改jar target(好多教程中,说最后执行 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下方
集成成功!