跌跌撞撞两天装Hadoop2.4.0的环境,今天终于可以尝试写点程序了,想了一想,不得其法,但有一点是肯定的,那就是需要用eclipse,查了一上午的资料,怎么讲的都有,最后锁定了这个帖子,hadoop2x-eclipse-plugin。想用Github下载,但是最后下载失败,页面右侧有个Download ZIP,用这个下载成功。下边来说说我的整个制作过程吧:
想导入到eclipse中制作,但是导入进去之后觉得麻烦就算了,直接在win7 64位、JDK1.6、ANT1.8的环境下以命令行运行
依葫芦画瓢,设置eclipse的目录和hadoop的目录,在没有修改任何文件的情况下直接运行
D:\SDK\hadoop2x-eclipse-plugin-master\src\contrib\eclipse-plugin>ant jar -Dversion=2.4.0 -Declipse.home=D:\WorkTools\MyEclipse10\Common -Dhadoop.home=D:\SDK\hadoop-2.4.0
在ivy-resolve-common处卡了大概138分钟,最后build失败,查看原因有两个,一个是找不到4个依赖包,一个是找不到1个核心包
依赖包分别是这些,可能是换路径了吧:
https://oss.sonatype.org/content/groups/public/com/google/google/1/google-1.jar
https://oss.sonatype.org/content/groups/public/net/java/jvnet-parent/1/jvnet-parent-1.jar
https://oss.sonatype.org/content/groups/public/com/sun/jersey/contribs/jersey-contribs/1.9/jersey-contribs-1.9.jar
https://oss.sonatype.org/content/groups/public/org/eclipse/jetty/jetty-parent/14/jetty-parent-14.jar
核心包是commons-lang-2.5.jar
想了一下,觉得那四个依赖包似乎没什么用,便想跳过那个步骤,想直接进行编译插件的步骤,便修改了“hadoop2x-eclipse-plugin-master\src\contrib\eclipse-plugin\build.xml”文件
<target depends="init, ivy-retrieve-common" unless="skip.contrib"> 去掉depends
核心包去hadoop2.4目录找,发现hadoop2.4用的commons-lang-2.6.jar,便在build.xml中找到相应位置改为2.6,这个需要说的是作者可能偷懒,在拷贝文件中使用的是变量,在配置信息中直接使用了2.5,不统一,变量配置信息在“hadoop2x-eclipse-plugin-master\ivy\libraries.properties”文件中,搜索“commons-lang.version”将对应的版本改为2.6,好了,在命令行下运行ant,成功在“hadoop2x-eclipse-plugin-master\build\contrib\eclipse-plugin”下生成插件
兴奋的拿着插件跟myeclipse10里试,失败(插件压根不出现),跟eclipse3.7里试,失败(插件能出现,但是无法正常使用,新增不了location)
拿着现成的2.2的插件均可以正常使用
后来经过排查原因myeclipse10里是因为插件放的位置不对,不能直接放到plugin里;eclipse3.7里失败是因为插件还缺少包
如何排查的呢?看eclipse的启动日志,这个日志在workplace中的.metadata文件下的.log文件,在eclipse3.7里报的错误是无法初始化hadoop,很郁闷,没太大帮助,于是就上eclilpse的官网下载了最新版的eclipse4.3.2,将ant语句改为
D:\SDK\hadoop2x-eclipse-plugin-master\src\contrib\eclipse-plugin>ant jar -Dversion=2.4.0 -Declipse.home=D:\WorkTools\eclipse4.3.2 -Dhadoop.home=D:\SDK\hadoop-2.4.0
对,改为以eclipse4.3.2为eclipse目录(这个配置主要就是为生成eclipse插件提供jar包支持),生成插件后放到eclipse4.3.2的plugins里,启动eclipse并观察日志,抛出异常
java.lang.NoClassDefFoundError: org/apache/commons/collections/map/UnmodifiableMap
------------------------------------------------最终的build.xml文件,修改的地方有注释---------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project default="jar">
<import file="../build-contrib.xml"/>
<path>
<fileset dir="${eclipse.home}/plugins/">
<include/>
<include/>
<include/>
<include/>
<include/>
<include/>
<include/>
<include/>
<include/>
<include/>
</fileset>
</path>
<path>
<fileset dir="${hadoop.home}/share/hadoop/mapreduce">
<include/>
</fileset>
<fileset dir="${hadoop.home}/share/hadoop/hdfs">
<include/>
</fileset>
<fileset dir="${hadoop.home}/share/hadoop/common">
<include/>
</fileset>
</path>
<path>
<pathelement location="${build.classes}"/>
<path refid="eclipse-sdk-jars"/>
<path refid="hadoop-sdk-jars"/>
</path>
<target unless="eclipse.home">
<property value="yes"/>
<echo message="eclipse.home unset: skipping eclipse plugin"/>
</target>
<!-- 这里我最后删除了depends="init, ivy-retrieve-common" -->
<target 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 depends="compile" unless="skip.contrib">
<mkdir dir="${build.dir}/lib"/>
<copy todir="${build.dir}/lib/" verbose="true">
<fileset dir="${hadoop.home}/share/hadoop/mapreduce">
<include/>
</fileset>
</copy>
<copy todir="${build.dir}/lib/" verbose="true">
<fileset dir="${hadoop.home}/share/hadoop/common">
<include/>
</fileset>
</copy>
<copy todir="${build.dir}/lib/" verbose="true">
<fileset dir="${hadoop.home}/share/hadoop/hdfs">
<include/>
</fileset>
</copy>
<copy todir="${build.dir}/lib/" verbose="true">
<fileset dir="${hadoop.home}/share/hadoop/yarn">
<include/>
</fileset>
</copy>