hadoop eclipse插件编译

由于hadoop 0.20之后不再提供eclipse插件,只提供源码自己进行编译,这里介绍eclipse插件编译的方法(以hadoop2.4.1为例)。 首先下载hadoop2x-eclipse-plugin-master,https://github.com/winghc/hadoop2x-eclipse-plugin 打开eclipse,新建一个项目。 解压下载的hadoop2x-eclipse-plugin-master.zip,在src/contrib目录下将以下5个文件拷贝到项目中。 会看到错误信息。这里打开build.xml,用以下代码进行覆盖

<project default="jar" name="eclipse-plugin">
	<property name="jdk.home" value="/home/zhangjun/jdk1.8.0_20" />
	    <property name="hadoop.version" value="2.4.1" />
	    <property name="hadoop.home" value="/home/zhangjun/hadoop-2.4.1" />
	    <property name="eclipse.version" value="3.6.1" />
	    <property name="eclipse.home" value="/usr/lib64/eclipse" />
	    <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>
	    	<fileset dir ="${eclipse.home}/dropins/jdt/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>
	    	<fileset dir ="${eclipse.home}/dropins/sdk/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>

在build.xml中单击右键,选择run AS,选择ant build(这里第一次编译出错,参考参考链接3进行了修改)。就会发现项目中多了一个build文件夹。     参考链接: 1、http://www.cnblogs.com/zxub/p/3884030.html 2、http://f.dataguru.cn/thread-356629-1-1.html 3、http://stackoverflow.com/questions/18806784/hadoop-1-2-1-plug-in-with-eclipse-indigo-3-7-2-ubuntu-12-04-error

Leave a Reply

Your email address will not be published. Required fields are marked *