由于1.0之后hadoop已经不自带eclipse的插件包了,所以得需要我们自己编译源码生成插件包。
eclipse的目录在/root/eclipse下面
总结一下如下的四步来完成编译eclipse插件的过程
步骤操作1进入/root/hadoop-1.2.0/src/contrib/eclipse-plugin下面,修改build.xml2进入/root/hadoop-1.2.0/src/contrib下面,修改build-contrib.xml3/root/hadoop-1.2.0/src/contrib/eclipse-plugin/META-INF下面,修改MANIFEST.MF文件4使用shell命令进入/root/hadoop-1.2.0/src/contrib/eclipse-plugin下面,执行ant命令进行构建
下面散仙就来详细介绍下,每一步具体怎么操作,在第一步里我们需要向build.xml里面,加入的内容有
1,eclipse的根目录.
2.hadoop的版本号.
3.hadoop的一些引用包.
4,在javac里加入 includeantruntime="on".
内容如下所示:
<!-- 1,2步的配置 -->
<propertyname="eclipse.home"location="/root/eclipse"/>
<propertyname="version"value="1.2.0"/>
<!--第3步的配置 -->
<copyfile="${hadoop.root}/hadoop-core-${version}.jar"tofile="${build.dir}/lib/hadoop-core.jar"verbose="true"/>
<copyfile="${hadoop.root}/lib/commons-cli-${commons-cli.version}.jar"tofile="${build.dir}/lib/commons-cli.jar"verbose="true"/>
<copyfile="${hadoop.root}/lib/commons-configuration-1.6.jar"tofile="${build.dir}/lib/commons-configuration.jar"verbose="true"/>
<copyfile="${hadoop.root}/lib/commons-httpclient-3.0.1.jar"tofile="${build.dir}/lib/commons-httpclient.jar"verbose="true"/>
<copyfile="${hadoop.root}/lib/commons-lang-2.4.jar"tofile="${build.dir}/lib/commons-lang.jar"verbose="true"/>
<copyfile="${hadoop.root}/lib/jackson-core-asl-1.8.8.jar"tofile="${build.dir}/lib/jackson-core-asl.jar"verbose="true"/>
<copyfile="${hadoop.root}/lib/jackson-mapper-asl-1.8.8.jar"tofile="${build.dir}/lib/jackson-mapper-asl.jar"verbose="true"/>
<!--第4步的配置 -->
includeantruntime="on">
散仙会在下文贴出整个XML,现在我们看第二大步的配置,修改build-contrib.xml,内容如下:
<!-- 原始的为off -->
lt;property name="javac.deprecation"value="on"/>
第三步的修改MANIFEST.MF内容如下:
Bundle-ClassPath: classes/,lib/commons-cli.jar,lib/commons-httpclient.jar,lib/hadoop-core.jar,lib/jackson-mapper-asl.jar,lib/commons-configuration.jar,lib/commons-lang.jar,lib/jackson-core-asl.jar
第四步执行命令:截图如下:
最后,插件类生成的目录,截图如下:
下面散仙给出所有配置的全部信息,以供参考,下图的是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 information regarding copyright ownership.
The ASF licenses this file to You 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.
-->
<!-- build.xml -->
<projectdefault="jar"name="eclipse-plugin">
<importfile="../build-contrib.xml"/>
<propertyname="eclipse.home"location="/root/eclipse"/>
<propertyname="version"value="1.2.0"/>
<pathid="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"/>
<includename="org.eclipse.jface*.jar"/>
<includename="org.eclipse.team.cvs.ssh2*.jar"/>
<includename="com.jcraft.jsch*.jar"/>
</fileset>
</path>
<!-- Override classpath to include Eclipse SDK jars -->
<pathid="classpath">
<pathelementlocation="${build.classes}"/>
<pathelementlocation="${hadoop.root}/build/classes"/>
<filesetdir="${hadoop.root}">
<includename="**/*.jar"/>
</fileset>
<pathrefid="eclipse-sdk-jars"/>
</path>
<!-- Skip building if eclipse.home is unset. -->
<targetname="check-contrib"unless="eclipse.home">
<propertyname="skip.contrib"value="yes"/>
<echomessage="eclipse.home unset: skipping eclipse plugin"/>
</target>
<targetname="compile"depends="init, ivy-retrieve-common"unless="skip.contrib">
<echomessage="contrib: ${name}"/>
<javac
encoding="${build.encoding}"
srcdir="${src.dir}"
includes="**/*.java"
destdir="${build.classes}"
debug="${javac.debug}"
deprecation="${javac.deprecation}"
includeantruntime="on">
<classpathrefid="classpath"/>
</javac>
</target>
<!-- Override jar target to specify manifest -->
<targetname="jar"depends="compile"unless="skip.contrib">
<mkdirdir="${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"/>-->
<copyfile="${hadoop.root}/hadoop-core-${version}.jar"tofile="${build.dir}/lib/hadoop-core.jar"verbose="true"/>
<copyfile="${hadoop.root}/lib/commons-cli-${commons-cli.version}.jar"tofile="${build.dir}/lib/commons-cli.jar"verbose="true"/>
<copyfile="${hadoop.root}/lib/commons-configuration-1.6.jar"tofile="${build.dir}/lib/commons-configuration.jar"verbose="true"/>
<copyfile="${hadoop.root}/lib/commons-httpclient-3.0.1.jar"tofile="${build.dir}/lib/commons-httpclient.jar"verbose="true"/>
<copyfile="${hadoop.root}/lib/commons-lang-2.4.jar"tofile="${build.dir}/lib/commons-lang.jar"verbose="true"/>
<copyfile="${hadoop.root}/lib/jackson-core-asl-1.8.8.jar"tofile="${build.dir}/lib/jackson-core-asl.jar"verbose="true"/>
<copyfile="${hadoop.root}/lib/jackson-mapper-asl-1.8.8.jar"tofile="${build.dir}/lib/jackson-mapper-asl.jar"verbose="true"/>
<jar
jarfile="${build.dir}/hadoop-${name}-${version}.jar"
manifest="${root}/META-INF/MANIFEST.MF">
<filesetdir="${build.dir}"includes="classes/ lib/"/>
<filesetdir="${root}"includes="resources/ plugin.xml"/>
</jar>
</target>
</project>
build-contrib.xml的核心配置如下:只有一个地方,notepad++,定位截图如下:
<propertyname="javac.deprecation"value="on"/>
下面是MANIFEST.MF里面的内容
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: MapReduce Tools for Eclipse
Bundle-SymbolicName: org.apache.hadoop.eclipse;singleton:=true
Bundle-Version: 0.18
Bundle-Activator: org.apache.hadoop.eclipse.Activator
Bundle-Localization: plugin
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.jdt.launching,
org.eclipse.debug.core,
org.eclipse.jdt,
org.eclipse.jdt.core,
org.eclipse.core.resources,
org.eclipse.ui.ide,
org.eclipse.jdt.ui,
org.eclipse.debug.ui,
org.eclipse.jdt.debug.ui,
org.eclipse.core.expressions,
org.eclipse.ui.cheatsheets,
org.eclipse.ui.console,
org.eclipse.ui.navigator,
org.eclipse.core.filesystem,
org.apache.commons.logging
Eclipse-LazyStart: true
Bundle-ClassPath: classes/,lib/commons-cli.jar,lib/commons-httpclient.jar,lib/hadoop-core.jar,lib/jackson-mapper-asl.jar,lib/commons-configuration.jar,lib/commons-lang.jar,lib/jackson-core-asl.jar
Bundle-Vendor: Apache Hadoop
至此,已经ant编译完毕,截图如下
启动eclipse后,截图如下:
至此,插件已经完美生成,并运行,因为受上传限制的影响,所以散仙在这里上传不了这个jar包。
本文出自 “DavideyLee” 博客,请务必保留此出处http://davideylee.blog.51cto.com/8703117/1381074