1、根据hadoop版本下载相应jar包。我用的是hadoop-1.0.3,所以下载的是hadoop-eclipse-plugin-1.0.3.jar版本。
http://pan.baidu.com/share/link?shareid=2598441536&uk=3709331609&fid=2470815234
2、解压jar包,在Eclipse中Import导入hadoop-eclipse-plugin-1.0.3-src文件夹,导进去在Eclipse中我的项目名称为MapReduceTools。(hadoop-eclipse-plugin-1.0.3-src为hadoop-eclipse-plugin-1.0.3.jar解压后所得文件夹)
3、把hadoop-eclipse-plugin-1.0.3-src文件夹下的build-contrib.xml文件拷贝到MapReduceTools项目根目录底下。
4、修改build-contrib.xml
找到<property name="hadoop.root" location="${root}/../../../"/>修改location为hadoop的实际解压目录
例如我的hadoop实际解压目录为:E:\qjay\hadoop\src\hadoop-1.0.3
则修改为:<property name="hadoop.root" location="E:/qjay/hadoop/src/hadoop-1.0.3"/>
查找<property name="eclipse.home" location="Eclipse安装目录"/>
<property name="version" value="Hadoop安装版本"/>,如果没有自己添加
例如我的为:<property name="eclipse.home" location="E:/eclipse"/>
<property name="version" value="1.0.3"/>
5、修改build.xml
找到<import file="../build-contrib.xml"/>,改为<import file="build-contrib.xml"/>
因为这个我们已经将build-contrib.xml文件放到MapReduceTools项目的根目录底下了。
6、添加hadoop-core的jar包
找到<path id="classpath">,在下面添加 <pathelement location="${hadoop.root}/hadoop-core-1.0.3.jar"/>
“hadoop-core-1.0.3.jar”根据自己的版本可能会有所不同,可以到${hadoop.root}/下边去找到相应的jar包。我的${hadoop.root}为“E:\qjay\hadoop\src\hadoop-1.0.3”就是hadoop的实际解压目录。
7、复制E:\qjay\hadoop\src\hadoop-1.0.3\hadoop-core-1.0.3.jar 到E:\qjay\hadoop-eclipse-plugin\hadoop-eclipse-plugin-1.0.3-src\eclipse-plugin\build\hadoop-core-1.0.3.jar;
复制E:\qjay\hadoop\src\hadoop-1.0.3\lib\commons-cli-1.2.jar到E:\qjay\hadoop-eclipse-plugin\hadoop-eclipse-plugin-1.0.3-src\eclipse-plugin\build\ivy\lib\Hadoop\common\commons-cli-1.2.jar,
如果上述目录没有则新建一下。
8、修改build.xml
<!-- Override jar target to specify manifest -->
<target name="jar" depends="compile" unless="skip.contrib">
<mkdir dir="${build.dir}/lib"/>
<!--此处我的${build.dir}为E:\qjay\hadoop\src\hadoop-1.0.3\build\contrib\eclipse-plugin-->
<copy file="${hadoop.root}/hadoop-core-1.0.3.jar" tofile="${build.dir}/lib/hadoop-core.jar" verbose="true"/>
<!--因为${hadoop.root}为“E:\qjay\hadoop\src\hadoop-1.0.3。所以此处“${hadoop.root}/hadoop-core-1.0.3.jar”会因为版本的不同而不同,我们可以到hadoop的安装目录下(${hadoop.root})找到相应目录下的相应jar包,后边情况-加粗的几行情况相似,依次类推。->
<copy file="${hadoop.root}/lib/commons-cli-1.2.jar" todir="${build.dir}/lib" verbose="true"/><!--windoop-->
<copy file="${hadoop.root}/lib/commons-configuration-1.6.jar" todir="${build.dir}/lib" verbose="true"/><!--windoop-->
<copy file="${hadoop.root}/lib/commons-httpclient-3.0.1.jar" todir="${build.dir}/lib" verbose="true"/><!--windoop-->
<copy file="${hadoop.root}/lib/commons-lang-2.4.jar" todir="${build.dir}/lib" verbose="true"/><!--windoop-->
<copy file="${hadoop.root}/lib/jackson-mapper-asl-1.8.8.jar" todir="${build.dir}/lib" verbose="true"/><!--windoop-->
<copy file="${hadoop.root}/lib/jackson-core-asl-1.8.8.jar" todir="${build.dir}/lib" verbose="true"/><!--windoop-->
<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>
9、修改MANIFEST.MF文件(在E:\qjay\hadoop-eclipse-plugin\hadoop-eclipse-plugin-1.0.3-src\eclipse-plugin\META-INF目录下)
“Bundle-ClassPath”这一栏加入如下信息:
lib/commons-cli-1.2.jar,lib/commons-configuration-1.6.jar,
lib/commons-httpclient-3.0.1.jar,lib/commons-lang-2.4.jar,lib/jackson-core-asl-1.8.8.jar,
lib/jackson-mapper-asl-1.8.8.jar
(我们加入的这些信息中,相应jar会根据版本不同而变化,可以直接将上边第8条加入的<copy>dsfffffffffffffffff</copy>语句中对应的jar包名拷贝过来。)
10、在Eclipse中运行MapReduceTools项目。(鼠标选中build.xml文件,单击右键选择Run As---->Ant Build)
如果出现以下信息:
compile:
[echo] contrib: eclipse-plugin
[javac] E:\qjay\hadoop-eclipse-plugin\hadoop-eclipse-plugin-1.0.3-src\eclipse-plugin\build.xml:61: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
11、则修改build.xml
<target name="compile" depends="init, ivy-retrieve-common" unless="skip.contrib">
将<javac>标签中加入includeantruntime="on"
Eg:
<target name="compile" depends="init, ivy-retrieve-common" unless="skip.contrib">
<javac
encoding="${build.encoding}"
srcdir="${src.dir}"
includes="**/*.java"
destdir="${build.classes}"
debug="${javac.debug}" includeantruntime="on">
<classpath refid="classpath"/>
</javac>
</target>
重新编译,控制台打印信息为以下:
Buildfile: E:\qjay\hadoop-eclipse-plugin\hadoop-eclipse-plugin-1.0.3-src\eclipse-plugin\build.xml
[echo] E:\qjay\hadoop\src\hadoop-1.0.3\build\contrib\eclipse-plugin
check-contrib:
init:
[echo] contrib: eclipse-plugin
[echo] E:\qjay\hadoop\src\hadoop-1.0.3\build\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:\qjay\hadoop\src\hadoop-1.0.3\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:\qjay\hadoop\src\hadoop-1.0.3\ivy\ivysettings.xml
ivy-resolve-common:
[ivy:resolve] :: resolving dependencies :: org.apache.hadoop#eclipse-plugin;working@lango-PC
[ivy:resolve] confs: [common]
[ivy:resolve] found commons-logging#commons-logging;1.0.4 in maven2
[ivy:resolve] found log4j#log4j;1.2.15 in maven2
[ivy:resolve] :: resolution report :: resolve 78ms :: artifacts dl 0ms
---------------------------------------------------------------------
| | modules || artifacts |
| conf | number| search|dwnlded|evicted|| number|dwnlded|
---------------------------------------------------------------------
| common | 2 | 0 | 0 | 0 || 2 | 0 |
---------------------------------------------------------------------
ivy-retrieve-common:
[ivy:retrieve] :: retrieving :: org.apache.hadoop#eclipse-plugin [sync]
[ivy:retrieve] confs: [common]
[ivy:retrieve] 0 artifacts copied, 2 already retrieved (0kB/16ms)
[ivy:cachepath] DEPRECATED: 'ivy.conf.file' is deprecated, use 'ivy.settings.file' instead
[ivy:cachepath] :: loading settings :: file = E:\qjay\hadoop\src\hadoop-1.0.3\ivy\ivysettings.xml
compile:
[echo] contrib: eclipse-plugin
jar:
BUILD SUCCESSFUL
Total time: 1 second
12、编译成功后在E:\qjay\hadoop\src\hadoop-1.0.3\build\contrib\eclipse-plugin文件夹下产生hadoop-eclipse-plugin-1.0.3.jar文件(根据自己版本不同可能生成的jar包名称有差异)。将hadoop-eclipse-plugin-1.0.3.jar拷贝到E:\eclipse\plugins下(Eclipse安装目录下的plugins文件夹下)。
13、重启Eclipse,打开Windows----->Open Perspective----->Other------->如果有Map/Reduce则成功。
Eg:
在编译时我主要参考的是这几位前辈的配置经验:
2、http://www.360doc.com/content/13/0727/22/13159363_303018432.shtml
3、http://blog.csdn.net/arbel/article/details/7674750
4、http://www.oschina.net/question/565065_113586
5、http://www.oschina.net/question/256028_110890
6、http://www.oschina.net/question/256028_110890
对以上几位前辈表示感谢,如果没有你们的经验我可能还要走很多弯路,谢谢!。
来源:oschina
链接:https://my.oschina.net/u/870039/blog/190840