当前位置: 代码迷 >> Eclipse >> hadoop1.2.1停编译及安装eclipse4.2插件
  详细解决方案

hadoop1.2.1停编译及安装eclipse4.2插件

热度:254   发布时间:2016-04-23 01:06:41.0
hadoop1.2.1下编译及安装eclipse4.2插件

转载请注明出处:http://hanlaiming.freetzi.com/?p=115

hadoop1.2.1环境安装完成后,准备着手开发Mapreduce程序,但是总在文本里编辑java代码肯定不是回事,所以开始安装eclipse插件。

我在安装前参考了这篇博文http://blog.csdn.net/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文件

找到:<path id=”classpath”>

然后添加

  1. <fileset dir=”${hadoop.root}/”>
  2.        <include name=”*.jar”/>
  3. </fileset>
再找到<target name=”jar” depends=”compile” unless=”skip.contrib”>
删除或者注释掉下边的两个<copy file的内容,然后添加 

  1. <copy file=”${hadoop.root}/hadoop-core-${version}.jar” tofile=”${build.dir}/lib/hadoop-core.jar” verbose=”true”/>
  2. <copy file=”${hadoop.root}/lib/commons-cli-1.2.jar”  todir=”${build.dir}/lib” verbose=”true”/>
  3. <copy file=”${hadoop.root}/lib/commons-lang-2.4.jar”  todir=”${build.dir}/lib” verbose=”true”/>
  4. <copy file=”${hadoop.root}/lib/commons-configuration-1.6.jar”  todir=”${build.dir}/lib” verbose=”true”/>
  5. <copy file=”${hadoop.root}/lib/jackson-mapper-asl-1.8.8.jar”  todir=”${build.dir}/lib” verbose=”true”/>
  6. <copy file=”${hadoop.root}/lib/jackson-core-asl-1.8.8.jar”  todir=”${build.dir}/lib” verbose=”true”/>
  7. <copy file=”${hadoop.root}/lib/commons-httpclient-3.0.1.jar”  todir=”${build.dir}/lib” verbose=”true”/>

4,最终修改后的build.xml文件为:

最后修改过的build.xml如下:

  1. ?xml version=”1.0″ encoding=”UTF-8″ standalone=”no”?>
  2. <!–
  3.    Licensed to the Apache Software Foundation (ASF) under one or more
  4.    contributor license agreements.  See the NOTICE file distributed with
  5.    this work for additional information regarding copyright ownership.
  6.    The ASF licenses this file to You under the Apache License, Version 2.0
  7.    (the ”License”); you may not use this file except in compliance with
  8.    the License.  You may obtain a copy of the License at
  9.        http://www.apache.org/licenses/LICENSE-2.0
  10.    Unless required by applicable law or agreed to in writing, software
  11.    distributed under the License is distributed on an ”AS IS” BASIS,
  12.    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.    See the License for the specific language governing permissions and
  14.    limitations under the License.
  15. –>
  16. <project default=”jar” name=”eclipse-plugin”>
  17.   <import file=”../build-contrib.xml”/>
  18.   <path id=”eclipse-sdk-jars”>
  19.     <fileset dir=”${eclipse.home}/plugins/”>
  20.       <include name=”org.eclipse.ui*.jar”/>
  21.       <include name=”org.eclipse.jdt*.jar”/>
  22.       <include name=”org.eclipse.core*.jar”/>
  23.       <include name=”org.eclipse.equinox*.jar”/>
  24.       <include name=”org.eclipse.debug*.jar”/>
  25.       <include name=”org.eclipse.osgi*.jar”/>
  26.       <include name=”org.eclipse.swt*.jar”/>
  27.       <include name=”org.eclipse.jface*.jar”/>
  28.       <include name=”org.eclipse.team.cvs.ssh2*.jar”/>
  29.       <include name=”com.jcraft.jsch*.jar”/>
  30.     </fileset>
  31.   </path>
  32.   <!– Override classpath to include Eclipse SDK jars –>
  33.   <path id=”classpath”>
  34.     <pathelement location=”${build.classes}”/>
  35.     <pathelement location=”${hadoop.root}/build/classes”/>
  36.     <path refid=”eclipse-sdk-jars”/>
  37.     <fileset dir=”${hadoop.root}/”>
  38.         <include name=”*.jar”/>
  39.     </fileset>
  40.   </path>
  41.   <!– Skip building if eclipse.home is unset. –>
  42.   <target name=”check-contrib” unless=”eclipse.home”>
  43.     <property name=”skip.contrib” value=”yes”/>
  44.     <echo message=”eclipse.home unset: skipping eclipse plugin”/>
  45.   </target>
  46.  <target name=”compile” depends=”init, ivy-retrieve-common” unless=”skip.contrib”>
  47.     <echo message=”contrib: ${name}”/>
  48.     <javac
  49.      encoding=”${build.encoding}”
  50.      srcdir=”${src.dir}”
  51.      includes=”**/*.java”
  52.      destdir=”${build.classes}”
  53.      debug=”${javac.debug}”
  54.      deprecation=”${javac.deprecation}”>
  55.      <classpath refid=”classpath”/>
  56.     </javac>
  57.   </target>
  58.   <!– Override jar target to specify manifest –>
  59.   <target name=”jar” depends=”compile” unless=”skip.contrib”>
  60.     <mkdir dir=”${build.dir}/lib”/>
  61.   <!–  <copy file=”${hadoop.root}/build/hadoop-core-${version}.jar” tofile=”${build.dir}/lib/hadoop-core.jar” verbose=”true”/>
  62.     <copy file=”${hadoop.root}/build/ivy/lib/Hadoop/common/commons-cli-${commons-cli.version}.jar”  todir=”${build.dir}/lib” verbose=”true”/>–>
  63.     <copy file=”${hadoop.root}/hadoop-core-${version}.jar” tofile=”${build.dir}/lib/hadoop-core.jar” verbose=”true”/>
  64.     <copy file=”${hadoop.root}/lib/commons-cli-1.2.jar”  todir=”${build.dir}/lib” verbose=”true”/>
  65.     <copy file=”${hadoop.root}/lib/commons-lang-2.4.jar”  todir=”${build.dir}/lib” verbose=”true”/>
  66.     <copy file=”${hadoop.root}/lib/commons-configuration-1.6.jar”  todir=”${build.dir}/lib” verbose=”true”/>
  67.     <copy file=”${hadoop.root}/lib/jackson-mapper-asl-1.8.8.jar”  todir=”${build.dir}/lib” verbose=”true”/>
  68.     <copy file=”${hadoop.root}/lib/jackson-core-asl-1.8.8.jar”  todir=”${build.dir}/lib” verbose=”true”/>
  69.     <copy file=”${hadoop.root}/lib/commons-httpclient-3.0.1.jar”  todir=”${build.dir}/lib” verbose=”true”/>
  70.     <jar
  71.       jarfile=”${build.dir}/hadoop-${name}-${version}.jar”
  72.       manifest=”${root}/META-INF/MANIFEST.MF”>
  73.       <fileset dir=”${build.dir}” includes=”classes/ lib/”/>
  74.       <fileset dir=”${root}” includes=”resources/ plugin.xml”/>
  75.     </jar>
  76.   </target>
  77. </project>

5,修改build-contrib.xml文件

添加如下路径

  1. <property name=”version” value=”1.2.1″/>
  2.   <property name=”ivy.version” value=”2.1.0″/>
  3.   <property name=”eclipse.home” location=”/home/summerdg/eclipse”/>

6,修改META-INF/MANIFEST.MF文件

最终文件为:

  1. Manifest-Version: 1.0
  2. Bundle-ManifestVersion: 2
  3. Bundle-Name: MapReduce Tools for Eclipse
  4. Bundle-SymbolicName: org.apache.hadoop.eclipse;singleton:=true
  5. Bundle-Version: 0.18
  6. Bundle-Activator: org.apache.hadoop.eclipse.Activator
  7. Bundle-Localization: plugin
  8. Require-Bundle: org.eclipse.ui,
  9.  org.eclipse.core.runtime,
  10.  org.eclipse.jdt.launching,
  11.  org.eclipse.debug.core,
  12.  org.eclipse.jdt,
  13.  org.eclipse.jdt.core,
  14.  org.eclipse.core.resources,
  15.  org.eclipse.ui.ide,
  16.  org.eclipse.jdt.ui,
  17.  org.eclipse.debug.ui,
  18.  org.eclipse.jdt.debug.ui,
  19.  org.eclipse.core.expressions,
  20.  org.eclipse.ui.cheatsheets,
  21.  org.eclipse.ui.console,
  22.  org.eclipse.ui.navigator,
  23.  org.eclipse.core.filesystem,
  24.  org.apache.commons.logging
  25. Eclipse-LazyStart: true
  26. 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
  27. Bundle-Vendor: Apache Hadoop

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安装完成。