转载请注明出处:http://hanlaiming.freetzi.com/?p=115
hadoop1.2.1环境安装完成后,准备着手开发Mapreduce程序,但是总在文本里编辑java代码肯定不是回事,所以开始安装eclipse插件。
我在安装前参考了这篇博文http://blog.youkuaiyun.com/summerdg/article/details/12874841,在此谢谢博主了。
下面是我的安装步骤:
1,准备好安装版本
ubuntu12.04 hadoop1.2.1 eclipse4.2Juno
2,打开eclipse,File——Import——Existing Projects into Workspace,选择hadoop安装目录下/src/contrib/eclipse-plugin,点击Finish。这时eclipse导入了一个MapReduceTools的工程,下面进行文件配置。
3,打开MapReduceTools工程里的build.xml文件
找到:<pathid=”classpath”>
然后添加
- <filesetdir=”${hadoop.root}/”>
- <includename=”*.jar”/>
- </fileset>
- <copyfile=”${hadoop.root}/hadoop-core-${version}.jar”tofile=”${build.dir}/lib/hadoop-core.jar”verbose=”true”/>
- <copyfile=”${hadoop.root}/lib/commons-cli-1.2.jar”todir=”${build.dir}/lib”verbose=”true”/>
- <copyfile=”${hadoop.root}/lib/commons-lang-2.4.jar”todir=”${build.dir}/lib”verbose=”true”/>
- <copyfile=”${hadoop.root}/lib/commons-configuration-1.6.jar”todir=”${build.dir}/lib”verbose=”true”/>
- <copyfile=”${hadoop.root}/lib/jackson-mapper-asl-1.8.8.jar”todir=”${build.dir}/lib”verbose=”true”/>
- <copyfile=”${hadoop.root}/lib/jackson-core-asl-1.8.8.jar”todir=”${build.dir}/lib”verbose=”true”/>
- <copyfile=”${hadoop.root}/lib/commons-httpclient-3.0.1.jar”todir=”${build.dir}/lib”verbose=”true”/>
4,最终修改后的build.xml文件为:
- ?xmlversion=”1.0″encoding=”UTF-8″standalone=”no”?>
- <!–
- LicensedtotheApacheSoftwareFoundation(ASF)underoneormore
- contributorlicenseagreements.SeetheNOTICEfiledistributedwith
- thisworkforadditionalinformationregardingcopyrightownership.
- TheASFlicensesthisfiletoYouundertheApacheLicense,Version2.0
- (the”License”);youmaynotusethisfileexceptincompliancewith
- theLicense.YoumayobtainacopyoftheLicenseat
- http://www.apache.org/licenses/LICENSE-2.0
- Unlessrequiredbyapplicablelaworagreedtoinwriting,software
- distributedundertheLicenseisdistributedonan”ASIS”BASIS,
- WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied.
- SeetheLicenseforthespecificlanguagegoverningpermissionsand
- limitationsundertheLicense.
- –>
- <projectdefault=”jar”name=”eclipse-plugin”>
- <importfile=”../build-contrib.xml”/>
- <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>
- <!–OverrideclasspathtoincludeEclipseSDKjars–>
- <pathid=”classpath”>
- <pathelementlocation=”${build.classes}”/>
- <pathelementlocation=”${hadoop.root}/build/classes”/>
- <pathrefid=”eclipse-sdk-jars”/>
- <filesetdir=”${hadoop.root}/”>
- <includename=”*.jar”/>
- </fileset>
- </path>
- <!–Skipbuildingifeclipse.homeisunset.–>
- <targetname=”check-contrib”unless=”eclipse.home”>
- <propertyname=”skip.contrib”value=”yes”/>
- <echomessage=”eclipse.homeunset:skippingeclipseplugin”/>
- </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}”>
- <classpathrefid=”classpath”/>
- </javac>
- </target>
- <!–Overridejartargettospecifymanifest–>
- <targetname=”jar”depends=”compile”unless=”skip.contrib”>
- <mkdirdir=”${build.dir}/lib”/>
- <!–<copyfile=”${hadoop.root}/build/hadoop-core-${version}.jar”tofile=”${build.dir}/lib/hadoop-core.jar”verbose=”true”/>
- <copyfile=”${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-1.2.jar”todir=”${build.dir}/lib”verbose=”true”/>
- <copyfile=”${hadoop.root}/lib/commons-lang-2.4.jar”todir=”${build.dir}/lib”verbose=”true”/>
- <copyfile=”${hadoop.root}/lib/commons-configuration-1.6.jar”todir=”${build.dir}/lib”verbose=”true”/>
- <copyfile=”${hadoop.root}/lib/jackson-mapper-asl-1.8.8.jar”todir=”${build.dir}/lib”verbose=”true”/>
- <copyfile=”${hadoop.root}/lib/jackson-core-asl-1.8.8.jar”todir=”${build.dir}/lib”verbose=”true”/>
- <copyfile=”${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”>
- <filesetdir=”${build.dir}”includes=”classes/lib/”/>
- <filesetdir=”${root}”includes=”resources/plugin.xml”/>
- </jar>
- </target>
- </project>
5,修改build-contrib.xml文件
添加如下路径
- <propertyname=”version”value=”1.2.1″/>
- <propertyname=”ivy.version”value=”2.1.0″/>
- <propertyname=”eclipse.home”location=”/home/summerdg/eclipse”/>
6,修改META-INF/MANIFEST.MF文件
最终文件为:
- Manifest-Version:1.0
- Bundle-ManifestVersion:2
- Bundle-Name:MapReduceToolsforEclipse
- 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/hadoop-core.jar,lib/jackson-core-asl-1.8.8.jar,lib/jackson-mapper-asl-1.8.8.jar,lib/commons-configuration-1.6.jar,lib/commons-lang-2.4.jar,lib/commons-httpclient-3.0.1.jar,lib/commons-cli-1.2.jar
- Bundle-Vendor:ApacheHadoop
7,保存完毕后,开始编译我们自己的插件。右击MapReduceTools工程,选择Properties,选择Builders,点击右侧的New,命名为Plugin_Builder,选择Ant Builder,BuildFile选择MapReduceTools里的build.xml文件,然后点击确定。
8,开始编译。点击eclipse的Project选项,选择Build Project,然后编译成功。编译后的jar文件放在hadoop安装目录下的build文件夹里,contrib下,有个hadoop-eclipse-1.2.1.jar文件,将其赋值到eclipse下的plugin里。
Ps.我在这里遇到了一个问题,有一个警告,说是无法复制hadoop目录下的hadoop-core-${version}.jar文件,我暂时没解决,但是好像没什么影响,只是生成的jar文件是hadoop-eclipse-${version}.jar文件,如果有其他人遇到并且解决了,麻烦告诉我一下,我的解决方法是将名字改正确然后复制过去的,发现也可以用。
9.打开eclipse,打开Window——Preferences,选择左侧的Hadoop Map/Reduce,然后指定自己安装的hadoop目录,点击确定。再打开Window——Open Perspective——other,选择MapReduce蓝色的小象,此时下方出现MapReduce Location,右键单击New Hadoop Location,开始配置hadoop变量。
10,进入New Hadoop location后,定义你的location name,然后选择和你的hadoop目录下core-site.xml文件一致的主机名和端口,并在Advanced parameters里找到两个重要的参数,
修改 hadoop.tmp.dir 为你 hadoop 集群中设置的目录
修改 dfs.replication 为你 hdfs-site.xml 文件中配置的值
然后确定。此时确保你的hadoop服务已经开启,接下来就可以在左侧的DFS Location下找到你hadoop环境下的目录,以后如果编译程序也会很方便。
至此,hadoop-eclipse-1.2.1.jar安装完成。