简化 Hadoop 2.4.1 Eclpse 插件编译【原创】
昨天折騰hadoop2X的eclipse插件,從https://github.com/winghc/hadoop2x-eclipse-plugin把源碼搞下來(lái)后,很快搞定出來(lái)一個(gè),但是。。。New Hadoop Location時(shí),窗口出不來(lái),汗死,原因后面會(huì)說(shuō)明的。源碼難下,最后我會(huì)附上源碼包的。
仔細(xì)看了ant和ivy的文件之后,我發(fā)現(xiàn)了一個(gè)坑爹的現(xiàn)象,編譯一個(gè)插件,需要ivy么?!
ant用了好久了,還是自己寫一個(gè)的好。
查看了jar包,都是hadoop安裝目錄里面存在的,還需要連個(gè)毛線的網(wǎng)去檢測(cè)啊!看了下ivy的調(diào)試信息,也就那么些東西,直接干掉ivy!
重新寫了個(gè)build.xml,只要往目錄hadoop2x-eclipse-plugin-master/src/contrib/eclipse-plugin里面一丟,改改前5個(gè)屬性的值,直接跑“ant jar”就行了。
或者eclipse建立一個(gè)普通項(xiàng)目,把
META-INF resources src build.properties plugin.xml往項(xiàng)目一丟,再把build.xml丟進(jìn)去,改了前5個(gè)屬性值直接跑就行了。
build.xml內(nèi)容如下
<?xml version="1.0"?> <project name="eclipse-plugin" default="jar"><property name="jdk.home" value="G:/jdk/jdk1.6.0" /><property name="hadoop.version" value="2.4.1" /><property name="hadoop.home" value="G:/hadoop/hadoop-2.4.1" /><property name="eclipse.version" value="3.7" /><property name="eclipse.home" value="G:/MyEclipse10/Common" /><property name="root" value="${basedir}" /><property file="${root}/build.properties" /><property name="name" value="${ant.project.name}" /><property name="src.dir" location="${root}/src/java" /><property name="build.contrib.dir" location="${root}/build/contrib" /><property name="build.dir" location="${build.contrib.dir}/${name}" /><property name="build.classes" location="${build.dir}/classes" /><!-- all jars together --><property name="javac.deprecation" value="off" /><property name="javac.debug" value="on" /><property name="build.encoding" value="ISO-8859-1" /><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><path id="project-jars"><fileset file="${build.dir}/lib/*.jar" /></path><target name="init" unless="skip.contrib"><echo message="contrib: ${name}" /><mkdir dir="${build.dir}" /><mkdir dir="${build.classes}" /><mkdir dir="${build.dir}/lib" /><copy todir="${build.dir}/lib/" verbose="true"><fileset dir="${hadoop.home}/share/hadoop/mapreduce"><include name="hadoop*.jar" /><exclude name="*test*"/><exclude name="*example*"/></fileset><fileset dir="${hadoop.home}/share/hadoop/common"><include name="hadoop*.jar" /><exclude name="*test*"/><exclude name="*example*"/></fileset><fileset dir="${hadoop.home}/share/hadoop/hdfs"><include name="hadoop*.jar" /><exclude name="*test*"/><exclude name="*example*"/></fileset><fileset dir="${hadoop.home}/share/hadoop/yarn"><include name="hadoop*.jar" /><exclude name="*test*"/><exclude name="*example*"/></fileset><fileset dir="${hadoop.home}/share/hadoop/common/lib"><include name="protobuf-java-*.jar" /><include name="log4j-*.jar" /><include name="commons-cli-*.jar" /><include name="commons-collections-*.jar" /><include name="commons-configuration-*.jar" /><include name="commons-lang-*.jar" /><include name="jackson-core-asl-*.jar" /><include name="jackson-mapper-asl-*.jar" /><include name="slf4j-log4j12-*.jar" /><include name="slf4j-api-*.jar" /><include name="guava-*.jar" /><include name="hadoop-annotations-*.jar" /><include name="hadoop-auth-*.jar" /><include name="commons-cli-*.jar" /><include name="netty-*.jar" /></fileset></copy></target><target name="compile" depends="init" unless="skip.contrib"><echo message="contrib: ${name}" /><javac fork="true" executable="${jdk.home}/bin/javac" encoding="${build.encoding}" srcdir="${src.dir}" includes="**/*.java" destdir="${build.classes}" debug="${javac.debug}" deprecation="${javac.deprecation}" includeantruntime="on"><classpath refid="eclipse-sdk-jars" /><classpath refid="project-jars" /></javac></target><target name="jar" depends="compile" unless="skip.contrib"><pathconvert property="mf.classpath" pathsep=",lib/"><path refid="project-jars" /><flattenmapper /></pathconvert><jar jarfile="${build.dir}/hadoop-${hadoop.version}-eclipse-${eclipse.version}-plugin.jar" manifest="${root}/META-INF/MANIFEST.MF"><manifest><attribute name="Bundle-ClassPath" value="classes/,lib/${mf.classpath}" /></manifest><fileset dir="${build.dir}" includes="classes/ lib/" /><fileset dir="${root}" includes="resources/ plugin.xml" /></jar></target><target name="clean"><echo message="contrib: ${name}" /><delete dir="${build.dir}" /></target></project>?
最前面5個(gè)屬性中,jdk.home指定編譯時(shí)用的jdk,hadoop和eclipse版本號(hào)是用來(lái)給jar起名字的,hadoop.home是hadoop安裝目錄,會(huì)從里面提取需要的文件,eclipse.home是eclipse的安裝目錄,MyEclipse中是那個(gè)Common目錄。
原版中坑爹的jar包版本號(hào)無(wú)視了,MANIFEST.MF的classpath值也懶得去改了,都自動(dòng)了,雖然自動(dòng)會(huì)多了幾個(gè)值,但是總比少的好。
又回到最開(kāi)始的問(wèn)題,new hadoop location時(shí)的窗口問(wèn)題,是因?yàn)樯倭薱ommons-collections包,所以直接從hadoop安裝目錄把這個(gè)包拉進(jìn)來(lái)打包了,然后問(wèn)題解決!
用jdk1.6編譯了兩個(gè)插件包,MyEclipse10的和Eclipse4.4的,都能用。至于上傳文件時(shí)由于當(dāng)前用戶名導(dǎo)致的權(quán)限問(wèn)題,這個(gè)就是改配置或改代碼的事情了,我是編譯前直接在源碼里面加了兩行,反正插件隨便編譯一下就有了。
最后附上官方源碼,里面原先那個(gè)打包好的插件干掉了,都是舊的,還巨大無(wú)比!下載源碼包
轉(zhuǎn)載于:https://www.cnblogs.com/zxub/p/3884030.html
總結(jié)
以上是生活随笔為你收集整理的简化 Hadoop 2.4.1 Eclpse 插件编译【原创】的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 腾达 FH303 无线路由器设置固定IP
- 下一篇: 木兰诗翻译150字