Hadoop2.4.0 Eclipse插件制作及问题记录

问题导读:
1.build.xml文件的作用是什么?
2.hadoop2.4用的commons-lang-2.6.jar,在build.xml中该如何修改?
3.插件包的制作需要经过几个步骤?






参考hadoop2x-eclipse-plugin
说说我的整个制作过程吧:
想导入到eclipse中制作,但是导入进去之后觉得麻烦就算了,直接在win7 64位、JDK1.6、ANT1.8的环境下以命令行运行
依葫芦画瓢,设置eclipse的目录和hadoop的目录,在没有修改任何文件的情况下直接运行

  1. 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个核心包

  • 依赖包分别是这些,可能是换路径了吧:


  1. https://oss.sonatype.org/content/groups/public/com/google/google/1/google-1.jar

  2. https://oss.sonatype.org/content/groups/public/net/java/jvnet-parent/1/jvnet-parent-1.jar

  3. https://oss.sonatype.org/content/groups/public/com/sun/jersey/contribs/jersey-contribs/1.9/jersey-contribs-1.9.jar

  4. 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”文件




  1. <target name="compile" 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语句改为

  1. 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并观察日志,抛出异常


  1. java.lang.NoClassDefFoundError: org/apache/commons/collections/map/UnmodifiableMap

复制代码

  • yes~ 折腾了又两个多小时,终于让我抓住了,找到这个包,在build.xml中添加上,别忘了在配置信息中也要添加,就是文件最下边的attribute,如果想以后方便,版本号也可以通过变量形式在libraries.properties中维护,搞定后,重新运行ant

  • 终于行了,在myeclipse10下也可正常使用了(这么建立文件夹MyEclipse 10\dropins\hadoop\eclipse\plugins,把插件扔这个文件夹下边就行了)

------------------------------------------------最终的build.xml文件,修改的地方有注释---------------------------------------------------------------

  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>

  2. <project default="jar" name="eclipse-plugin">

  3.   <import file="../build-contrib.xml"/>

  4.   <path id="eclipse-sdk-jars">

  5.     <fileset dir="${eclipse.home}/plugins/">

  6.       <include name="org.eclipse.ui*.jar"/>

  7.       <include name="org.eclipse.jdt*.jar"/>

  8.       <include name="org.eclipse.core*.jar"/>

  9.       <include name="org.eclipse.equinox*.jar"/>

  10.       <include name="org.eclipse.debug*.jar"/>

  11.       <include name="org.eclipse.osgi*.jar"/>

  12.       <include name="org.eclipse.swt*.jar"/>

  13.       <include name="org.eclipse.jface*.jar"/>

  14.       <include name="org.eclipse.team.cvs.ssh2*.jar"/>

  15.       <include name="com.jcraft.jsch*.jar"/>

  16.     </fileset> 

  17.   </path>

  18.   <path id="hadoop-sdk-jars">

  19.     <fileset dir="${hadoop.home}/share/hadoop/mapreduce">

  20.       <include name="hadoop*.jar"/>

  21.     </fileset> 

  22.     <fileset dir="${hadoop.home}/share/hadoop/hdfs">

  23.       <include name="hadoop*.jar"/>

  24.     </fileset> 

  25.     <fileset dir="${hadoop.home}/share/hadoop/common">

  26.       <include name="hadoop*.jar"/>

  27.     </fileset> 

  28.   </path>

  29.   <path id="classpath">

  30.     <pathelement location="${build.classes}"/>

  31.     <path refid="eclipse-sdk-jars"/>

  32.     <path refid="hadoop-sdk-jars"/>

  33.   </path>

  34.   <target name="check-contrib" unless="eclipse.home">

  35.     <property name="skip.contrib" value="yes"/>

  36.     <echo message="eclipse.home unset: skipping eclipse plugin"/>

  37.   </target>

  38.         <!-- 这里我最后删除了depends="init, ivy-retrieve-common" -->

  39. <target name="compile" depends="init, ivy-retrieve-common" unless="skip.contrib">

  40.     <echo message="contrib: ${name}"/>

  41.     <javac

  42.      encoding="${build.encoding}"

  43.      srcdir="${src.dir}"

  44.      includes="**/*.java"

  45.      destdir="${build.classes}"

  46.      debug="${javac.debug}"

  47.      deprecation="${javac.deprecation}">

  48.      <classpath refid="classpath"/>

  49.     </javac>

  50.   </target>

  51.   <target name="jar" depends="compile" unless="skip.contrib">

  52.     <mkdir dir="${build.dir}/lib"/>

  53.     <copy  todir="${build.dir}/lib/" verbose="true">

  54.           <fileset dir="${hadoop.home}/share/hadoop/mapreduce">

  55.            <include name="hadoop*.jar"/>

  56.           </fileset>

  57.     </copy>

  58.     <copy  todir="${build.dir}/lib/" verbose="true">

  59.           <fileset dir="${hadoop.home}/share/hadoop/common">

  60.            <include name="hadoop*.jar"/>

  61.           </fileset>

  62.     </copy>

  63.     <copy  todir="${build.dir}/lib/" verbose="true">

  64.           <fileset dir="${hadoop.home}/share/hadoop/hdfs">

  65.            <include name="hadoop*.jar"/>

  66.           </fileset>

  67.     </copy>

  68.     <copy  todir="${build.dir}/lib/" verbose="true">

  69.           <fileset dir="${hadoop.home}/share/hadoop/yarn">

  70.            <include name="hadoop*.jar"/>

  71.           </fileset>

  72.     </copy>


  73.     <copy  todir="${build.dir}/classes" verbose="true">

  74.           <fileset dir="${root}/src/java">

  75.            <include name="*.xml"/>

  76.           </fileset>

  77.     </copy>

  78.     <copy file="${hadoop.home}/share/hadoop/common/lib/protobuf-java-${protobuf.version}.jar"  todir="${build.dir}/lib" verbose="true"/>

  79.     <copy file="${hadoop.home}/share/hadoop/common/lib/log4j-${log4j.version}.jar"  todir="${build.dir}/lib" verbose="true"/>

  80.     <copy file="${hadoop.home}/share/hadoop/common/lib/commons-cli-${commons-cli.version}.jar"  todir="${build.dir}/lib" verbose="true"/>

  81.     <copy file="${hadoop.home}/share/hadoop/common/lib/commons-configuration-${commons-configuration.version}.jar"  todir="${build.dir}/lib" verbose="true"/>

  82.     <copy file="${hadoop.home}/share/hadoop/common/lib/commons-lang-${commons-lang.version}.jar"  todir="${build.dir}/lib" verbose="true"/>

  83.     <!-- 下边这行是新增的,原来没有 -->

  84.     <copy file="${hadoop.home}/share/hadoop/common/lib/commons-collections-${commons-collections.version}.jar"  todir="${build.dir}/lib" verbose="true"/>

  85.     <copy file="${hadoop.home}/share/hadoop/common/lib/jackson-core-asl-${jackson.version}.jar"  todir="${build.dir}/lib" verbose="true"/>

  86.     <copy file="${hadoop.home}/share/hadoop/common/lib/jackson-mapper-asl-${jackson.version}.jar"  todir="${build.dir}/lib" verbose="true"/>

  87.     <copy file="${hadoop.home}/share/hadoop/common/lib/slf4j-log4j12-${slf4j-log4j12.version}.jar"  todir="${build.dir}/lib" verbose="true"/>

  88.     <copy file="${hadoop.home}/share/hadoop/common/lib/slf4j-api-${slf4j-api.version}.jar"  todir="${build.dir}/lib" verbose="true"/>

  89.     <copy file="${hadoop.home}/share/hadoop/common/lib/guava-${guava.version}.jar"  todir="${build.dir}/lib" verbose="true"/>

  90.     <copy file="${hadoop.home}/share/hadoop/common/lib/hadoop-auth-${hadoop.version}.jar"  todir="${build.dir}/lib" verbose="true"/>

  91.     <copy file="${hadoop.home}/share/hadoop/common/lib/commons-cli-${commons-cli.version}.jar"  todir="${build.dir}/lib" verbose="true"/>

  92.     <copy file="${hadoop.home}/share/hadoop/common/lib/netty-${netty.version}.jar"  todir="${build.dir}/lib" verbose="true"/>

  93.     <jar

  94.       jarfile="${build.dir}/hadoop-${name}-${version}.jar"

  95.       manifest="${root}/META-INF/MANIFEST.MF">

  96.       <manifest>

  97.          <attribute name="Bundle-ClassPath" 

  98.                 value="classes/, 

  99. lib/hadoop-mapreduce-client-core-${hadoop.version}.jar,

  100. lib/hadoop-mapreduce-client-common-${hadoop.version}.jar,

  101. lib/hadoop-mapreduce-client-jobclient-${hadoop.version}.jar,

  102. lib/hadoop-auth-${hadoop.version}.jar,

  103. lib/hadoop-common-${hadoop.version}.jar,

  104. lib/hadoop-hdfs-${hadoop.version}.jar,

  105. lib/protobuf-java-${protobuf.version}.jar,

  106. lib/log4j-${log4j.version}.jar,

  107. lib/commons-cli-1.2.jar,

  108. lib/commons-configuration-1.6.jar,

  109. lib/commons-httpclient-3.1.jar,

  110. <!-- 下边这行原来写的是commons-lang-2.5 -->

  111. lib/commons-lang-${commons-lang.version}.jar,

  112. <!-- 下边这行是新增的,原来没有 -->

  113. lib/commons-collections-${commons-collections.version}.jar,

  114. lib/jackson-core-asl-1.8.8.jar,

  115. lib/jackson-mapper-asl-1.8.8.jar,

  116. lib/slf4j-log4j12-1.7.5.jar,

  117. lib/slf4j-api-1.7.5.jar,

  118. lib/guava-${guava.version}.jar,

  119. lib/netty-${netty.version}.jar"/>

  120.          </manifest>

  121.       <fileset dir="${build.dir}" includes="classes/ lib/"/>

  122.       <fileset dir="${root}" includes="resources/ plugin.xml"/>

  123.     </jar>

  124.   </target>

  125. </project>


复制代码



你可能感兴趣的:(hadoop)