1:下载后Hadoop-1.1.2.tar.gz文件,里面包含源代码,并解压到E:\hadoop\hadoop-1.2.1
2:在eclipse导入工程,目录选择:E:\hadoop\hadoop-1.2.1\src\contrib\eclipse-plugin
3:在项目 MapReduceTools 中新建 lib 目录,将 hadoop-1.2.1 下的 hadoop-core-1.2.1.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 拷贝到该目录。
4:修改项目的Libraries
5:修改build-contrib.xml
将E:\hadoop\hadoop-1.2.1\src\contrib目录下的build-contrib.xml文件拷贝到项目目录中,注意:build-contrib.xml文件以eclipse-plugin是在同一级目录中,拷贝完成以后修改build-contrib.xml文件。修改的内容如下。
-
<property name="name" value="${ant.project.name}"/>
-
<property name="root" value="${basedir}"/>
-
<property name="version" value="1.2.1"/>
-
<property name="hadoop.root" location="E:/hadoop/hadoop-1.2.1"/>
-
<property name="eclipse.home" location="E:/work/eclipse-jee-kepler-SR2-win32/eclipse" />
这个是前面几行的内容
6:修改build.xml
如果导入项目的时候选择的是copy的话,需要E:\hadoop\hadoop-1.2.1\src\contrib\eclipse-plugin下的build.xml文件拷贝到项目目录中,不是的话直接修改。
下面是完整的内容:
-
<?xml version="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.
-
-->
-
-
<project default="jar" name="eclipse-plugin">
-
-
<import file="build-contrib.xml"/>
-
-
-
<path id="hadoop-jars">
-
<fileset dir="${hadoop.root}/">
-
<include name="hadoop-*.jar"/>
-
</fileset>
-
</path>
-
-
<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>
-
</path>
-
-
-
<path id="classpath">
-
<pathelement location="${build.classes}"/>
-
<pathelement location="${hadoop.root}/build/classes"/>
-
<path refid="eclipse-sdk-jars"/>
-
<path refid="hadoop-jars"/>
-
</path>
-
-
-
<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>
-
-
-
<target name="jar" depends="compile" unless="skip.contrib">
-
<mkdir dir="${build.dir}/lib"/>
-
-
<copy file="${hadoop.root}/hadoop-core-${version}.jar" tofile="${build.dir}/lib/hadoop-core-${version}.jar" verbose="true"/>
-
-
-
-
-
<copy file="${hadoop.root}/lib/commons-cli-1.2.jar" todir="${build.dir}/lib" verbose="true"/>
-
<copy file="${hadoop.root}/lib/commons-lang-2.4.jar" todir="${build.dir}/lib" verbose="true"/>
-
<copy file="${hadoop.root}/lib/commons-configuration-1.6.jar" todir="${build.dir}/lib" verbose="true"/>
-
<copy file="${hadoop.root}/lib/jackson-mapper-asl-1.8.8.jar" todir="${build.dir}/lib" verbose="true"/>
-
<copy file="${hadoop.root}/lib/jackson-core-asl-1.8.8.jar" todir="${build.dir}/lib" verbose="true"/>
-
<copy file="${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>
7:修改MANIFEST.MF
在Bundle-ClassPath添加下面的内容
-
Bundle-ClassPath: classes/,
-
lib/hadoop-core.jar,
-
lib/
8:Ant 编译
a. 右键 MapReduceTools 工程,Properties—>Builders—>New—>Ant Builder
b. 修改New_Builder编辑界面中的内容
Name (见名知意): hadoop_Builder
Buildfile (build.xml的位置): 项目路径下面\build.xml
3. 修改完成保存
4. 点击Project—>Build Project进行生成
点击Project—>Build Project开始进行生成,这时候我们会看到控制台输出一堆相关的编译信息,编译成功会看到在控制台输出 BUILD SUCCESSFUL 。编译结果在 E:\hadoop\hadoop-1.2.1\build\contrib\eclipse-plugin目录下。
-
Buildfile: E:\work\workspace1\MapReduceTools\build.xml
-
-
check-contrib:
-
-
init:
-
[echo] contrib: eclipse-plugin
-
-
init-contrib:
-
-
ivy-download:
-
[get] Getting: http://repo2.maven.org/maven2/org/apache/ivy/ivy/2.1.0/ivy-2.1.0.jar
-
[get] To: E:\hadoop\hadoop-1.2.1\ivy\ivy-2.1.0.jar
-
[get] Not modified - so not downloaded
-
-
ivy-probe-antlib:
-
-
ivy-init-antlib:
-
-
ivy-init:
-
[ivy:configure] :: Ivy 2.1.0 - 20090925235825 :: http://ant.apache.org/ivy/ ::
-
[ivy:configure] :: loading settings :: file = E:\hadoop\hadoop-1.2.1\ivy\ivysettings.xml
-
-
ivy-resolve-common:
-
-
ivy-retrieve-common:
-
[ivy:cachepath] DEPRECATED: 'ivy.conf.file' is deprecated, use 'ivy.settings.file' instead
-
[ivy:cachepath] :: loading settings :: file = E:\hadoop\hadoop-1.2.1\ivy\ivysettings.xml
-
-
compile:
-
[echo] contrib: eclipse-plugin
-
[javac] E:\work\workspace1\MapReduceTools\build.xml:69: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
-
-
jar:
-
BUILD SUCCESSFUL
-
Total time: 1 second
安装插件
安装插件到eclipse的话就需要将 hadoop-eclipse-plugin-1.2.1.jar 放入 到eclipse的plugins 目录下,重启 eclipse即可。
(责任编辑:IT) |