Linux下Hadoop Eclipse插件编译安装

来源:互联网 发布:java程序代码大全 编辑:程序博客网 时间:2024/05/21 22:55

我的hadoop是1.2.1版本的,在网上也有一些编译好的hadoop插件,但是还是自己动手,丰衣足食,以后版本更新的时候能自己编译插件,而且这样还能保证往eclipse里安装的时候不会出太多的问题。

主要是参考了这篇文章http://www.cnblogs.com/kinuxroot/archive/2013/05/06/linux_hadoop_eclipse_plugin.html

为方便查看,还是将其中信息粘贴过来。声明:我按照前面的解释部分一点点添加代码的时候没成功,使用了后面的整体文件,稍加修改之后才成功的,果然胡乱往里添加是不行的,毕竟版本也是不一样,有些地方还是不同。

1.先要加入eclipse的设定和hadoop的版本设定,我的eclipse安装在/home/kinuxroot/apps/eclipse下,所以我们要修改为:

<property name="eclipse.home" location="/home/kinuxroot/apps/eclipse"/><property name="version" value="1.1.2"/>

这一步,location中的路径请大家根据各自的实际路径进行修改。


2.我们需要引用hadoop的一些包,但是默认的classpath没有这些包(我们没有从头编译)。所以需要修改classpath
定位<path id="classpath">,加入:

<fileset dir="${hadoop.root}">    <include name="**/*.jar" /></fileset>

 

3.代码中使用了一些遗留功能,所以我们要修改deprecation的设定。
打开hadoop根路径下面的src/contrib/build-contrib.xml,定位

<property name="javac.deprecation" value="off"/>

然后修改成

<property name="javac.deprecation" value="on"/>

 

4.修改includeantruntime设置。定位compile的target,修改javac的设置,加入一个选项
     includeantruntime="on"
也就是将javac修改成

复制代码
<javac     encoding="${build.encoding}"     srcdir="${src.dir}"     includes="**/*.java"     destdir="${build.classes}"     debug="${javac.debug}"     deprecation="${javac.deprecation}"     includeantruntime="on">     <classpath refid="classpath"/></javac>
复制代码

 

5.jar打包的时候需要hadoop的一些jar文件,但是我们没有编译生成它,所以我们需要修改一下jar这个target。

另外,有几个jar是我们需要用到,而build.xml里面没有自动包含的,如果不包含它们,Eclipse连接Hadoop会出现failure to login错误,其实就是找不到类
找到

<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"/>

我们修改成

复制代码
<copy file="${hadoop.root}/hadoop-core-${version}.jar" tofile="${build.dir}/lib/hadoop-core.jar" verbose="true"/><copy file="${hadoop.root}/lib/commons-cli-${commons-cli.version}.jar"  tofile="${build.dir}/lib/commons-cli.jar" verbose="true"/><copy file="${hadoop.root}/lib/commons-configuration-1.6.jar"  tofile="${build.dir}/lib/commons-configuration.jar" verbose="true"/><copy file="${hadoop.root}/lib/commons-httpclient-3.0.1.jar"  tofile="${build.dir}/lib/commons-httpclient.jar" verbose="true"/><copy file="${hadoop.root}/lib/commons-lang-2.4.jar"  tofile="${build.dir}/lib/commons-lang.jar" verbose="true"/><copy file="${hadoop.root}/lib/jackson-core-asl-1.8.8.jar"  tofile="${build.dir}/lib/jackson-core-asl.jar" verbose="true"/><copy file="${hadoop.root}/lib/jackson-mapper-asl-1.8.8.jar"  tofile="${build.dir}/lib/jackson-mapper-asl.jar" verbose="true"/>
复制代码

6.但是这样,我们的jar文件还是不会自动部署到eclipse中,你可以手动复制,但是我们希望ant帮我们自动部署进去。
我们新建一个target,用来部署:

<target name="deploy" depends="jar" unless="skip.contrib"><copy file="${build.dir}/hadoop-${name}-${version}.jar"  todir="${eclipse.home}/plugins" verbose="true"/></target>

然后修改project的默认target,也就是将project修改成:

<project default="deploy" name="eclipse-plugin">

7.接下来一步我们要修改Hadoop根目录下的src/contrib/eclipse-plugin/META-INFO/MANIFEST.MF,修改这个jar的classpath。

找到这个文件的Bundle-ClassPath这一行,然后,修改成

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

8.执行ant,代码就会被编译,插件会被自动安装到eclipse的plugins目录中,打开eclipse就可以使用了(如果没有安装ant,
请去apache观望下载ant的二进制编译版)。另外编译时会自动联网下载需要的包,所以请保证网络通畅。

最后,我把我的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="deploy" name="eclipse-plugin">  <import file="../build-contrib.xml"/>  <property name="eclipse.home" location="/home/kinuxroot/apps/eclipse"/><!--这里的location改成本机的eclipse安装路径-->  <property name="version" value="1.1.2"/><!--这里的版本信息要改成和自己一样的,我就在这里出了错-->  <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>  <!-- Override classpath to include Eclipse SDK jars -->  <path id="classpath">    <pathelement location="${build.classes}"/>    <pathelement location="${hadoop.root}/build/classes"/>    <fileset dir="${hadoop.root}">        <include name="**/*.jar" />    </fileset>    <path refid="eclipse-sdk-jars"/>  </path>  <!-- Skip building if eclipse.home is unset. -->  <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}"     includeantruntime="on">     <classpath refid="classpath"/>    </javac>  </target>  <!-- Override jar target to specify manifest -->  <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.jar" verbose="true"/>    <copy file="${hadoop.root}/lib/commons-cli-${commons-cli.version}.jar"  tofile="${build.dir}/lib/commons-cli.jar" verbose="true"/>    <copy file="${hadoop.root}/lib/commons-configuration-1.6.jar"  tofile="${build.dir}/lib/commons-configuration.jar" verbose="true"/>    <copy file="${hadoop.root}/lib/commons-httpclient-3.0.1.jar"  tofile="${build.dir}/lib/commons-httpclient.jar" verbose="true"/>    <copy file="${hadoop.root}/lib/commons-lang-2.4.jar"  tofile="${build.dir}/lib/commons-lang.jar" verbose="true"/>    <copy file="${hadoop.root}/lib/jackson-core-asl-1.8.8.jar"  tofile="${build.dir}/lib/jackson-core-asl.jar" verbose="true"/>    <copy file="${hadoop.root}/lib/jackson-mapper-asl-1.8.8.jar"  tofile="${build.dir}/lib/jackson-mapper-asl.jar" verbose="true"/>    <echo message="${build.dir}"/>    <echo message="${root}"/>    <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>  <target name="deploy" depends="jar" unless="skip.contrib">    <copy file="${build.dir}/hadoop-${name}-${version}.jar"  todir="${eclipse.home}/plugins" verbose="true"/>  </target></project>

0 0
原创粉丝点击