`

Eclipse编译Hadoop 0.20.203源码

 
阅读更多

1、软件环境:

Eclipse:Indigo Service Release 1

Hadoop:Hadoop 0.20.203

 

2、设置系统环境变量

JAVA_HOME = C:\Program Files\Java\jdk1.6.0_25

ANT_HOME = D:\apache-ant-1.8.2

M2_HOME = D:\apache-maven-2.2.1

Path = %M2_HOME%\bin;%ANT_HOME%\bin

classpath = .;%JAVA_HOME%\lib\dt.jar

 

3、新建Java Project,把hadoop-0.20.203.0\src下面的core、hdfs和mapred三个文件夹拷贝到Eclipse src目录

4、在Eclipse下新建lib文件夹,并把hadoop-0.20.203.0\lib和hadoop-0.20.203.0\lib\jsp-2.1中的所有jar包拷贝到此目录,把ant jar包也拷贝到此目录



 

5、新建conf目录,把自定义hadoop配置文件(core-site.xml/hdfs-site.xml/mapred-site.xml/hadoop-env.sh/masters/slaves)以及hadoop-0.20.203.0\webapps拷贝到此目录

6、把hadoop-0.20.203.0\src\webapps拷贝到Eclipse JSP目录下

7、编写build.xml

 

<?xml version="1.0"?>

<project name="hadoop-0.20.203" default="compile-all">
 <property name="basedir" value="." />

 <property name="lib.dir" location="${basedir}/lib" />
 <property name="build.classes" location="${basedir}/build" />

 <property name="javac.debug" value="on" />
 <property name="javac.optimize" value="on" />
 <property name="javac.deprecation" value="off" />
 <property name="javac.version" value="1.6" />
 <property name="javac.args" value="-Xlint:unchecked" />
 <property name="javac.encoding" value="UTF-8" />

 <property name="src" value="${basedir}/src" />
 <!--<property name="hdfs.src" value="${basedir}/hdfs" />-->

 <property name="release.dir" value="${basedir}/release" />

 <property name="config.dir" value="${basedir}/conf" />
 <!--<property name="cmd.dir" value="${basedir}/cmd" />
 <property name="jre.dir" value="${cmd.dir}/jre" />-->

 <property name="jsp.path" value="${basedir}/webapps" />
 <property name="webapps.path" value="${basedir}/conf/webapps" />
 <property name="servlet.path" location="${jsp.path}/src" />
 <!--<property name="jre.version" value="1.6.0_21" />-->

 

 <path id="classpath">
  <fileset dir="${lib.dir}" id="libdir">
   <include name="**/*.jar" />
   <include name="**/*.zip" />
   <exclude name="**/excluded/" />
  </fileset>
 </path>

 <target name="init">
  <mkdir dir="${build.classes}" />
  <mkdir dir="${release.dir}" />
  <mkdir dir="${servlet.path}" />
 </target>


 <target name="clean_build_dir">
  <delete dir="${build.classes}" />
  <delete dir="${release.dir}" />
  <delete dir="${servlet.path}" />
 </target>


 <target name="clean-all-and-compile-all"
         depends="clean_build_dir,compile-all" />


 <!--///////////////////////Compile Area - Start ////////////////////////-->
 <target name="compile-all" depends="clean_build_dir,init,compile-jsp">
  <macro_javac srcdir="${src}" destdir="${build.classes}" />
  <macro_javac srcdir="${servlet.path}" destdir="${build.classes}" />
 </target>


 <!-- ====================================================== -->
 <!-- Generate Install Package                               -->
 <!-- ====================================================== -->
 <target name="tar-install-32" depends="jar-all">
  <macro_tar version="32" />
 </target>

 <target name="tar-install-64" depends="jar-all">
  <macro_tar version="64" />
 </target>

 <target name="tar-install" depends="tar-install-32,tar-install-64" />

 <!-- ====================================================== -->
 <!-- Macro definitions                                      -->
 <!-- ====================================================== -->
 <macrodef name="macro_tar" description="Worker Macro for tar">
  <attribute name="version" />
  <sequential>
   <tar compression="gzip"
        longfile="gnu"
        destfile="${release.dir}/${ant.project.name}-@{version}.tar.gz">

    <tarfileset dir="${release.dir}" mode="664" prefix="/${ant.project.name}/lib">
     <include name="*.jar" />
    </tarfileset>

    <tarfileset dir="${config.dir}" mode="755" prefix="/${ant.project.name}/conf">
     <include name="**/*" />
    </tarfileset>

    <tarfileset dir="${lib.dir}/" mode="755" prefix="/${ant.project.name}/lib">
     <include name="**/*" />
    </tarfileset>

    <!--<tarfileset dir="${cmd.dir}"
                prefix="/cfs/bin"
                mode="777"
                dirmode="777">
     <include name="*" />
     <exclude name="**/.svn" />
     <exclude name="**/py" />
    </tarfileset>

    <tarfileset dir="${jre.dir}/linux@{version}/${jre.version}"
                mode="777"
                dirmode="777"
                prefix="/cfs/jre">
     <include name="**/*" />
    </tarfileset>-->

   </tar>
  </sequential>
 </macrodef>

 <target name="compile-jsp">
  <taskdef classname="org.apache.jasper.JspC" name="jsp-compile">
   <classpath refid="classpath" />
  </taskdef>
  <jsp-compile uriroot="${jsp.path}/datanode"
               outputdir="${servlet.path}"
               package="org.apache.hadoop.hdfs.server.datanode"
               webxml="${webapps.path}/datanode/WEB-INF/web.xml">
  </jsp-compile>

  <jsp-compile uriroot="${jsp.path}/hdfs"
               outputdir="${servlet.path}"
               package="org.apache.hadoop.hdfs.server.namenode"
               webxml="${webapps.path}/hdfs/WEB-INF/web.xml">
  </jsp-compile>

  <jsp-compile uriroot="${jsp.path}/job"
               outputdir="${servlet.path}"
               package="org.apache.hadoop.mapred"
               webxml="${webapps.path}/job/WEB-INF/web.xml">
  </jsp-compile>
  
  <jsp-compile uriroot="${jsp.path}/task"
               outputdir="${servlet.path}"
               package="org.apache.hadoop.mapred"
               webxml="${webapps.path}/task/WEB-INF/web.xml">
  </jsp-compile>
 </target>

 <!-- ====================================================== -->
 <!-- Core jar                                               -->
 <!-- ====================================================== -->
 <target name="jar-all" depends="compile-all" description="Make jar of cfs">
  <jar jarfile="${release.dir}/${ant.project.name}.jar">
   <manifest>
    <section name="cn/com/cncloud">
     <attribute name="Implementation-Title" value="${ant.project.name}" />
     <attribute name="Implementation-Version" value="2" />
     <attribute name="Implementation-Vendor" value="cncloud.com.cn" />
    </section>
   </manifest>
   <fileset dir="${build.classes}">
    <exclude name="src/**" />
   </fileset>
  </jar>
 </target>


 <macrodef name="macro_javac" description="Worker Macro for compile">
  <attribute name="destdir" />
  <attribute name="srcdir" />
  <sequential>
   <javac encoding="${javac.encoding}"
          srcdir="@{srcdir}"
          destdir="@{destdir}"
          debug="${javac.debug}"
          optimize="${javac.optimize}"
          target="${javac.version}"
          source="${javac.version}"
          deprecation="${javac.deprecation}"
          includes="**/*">

    <compilerarg line="${javac.args}" />

    <classpath refid="classpath" />
   </javac>

   <copy todir="@{destdir}">
    <fileset dir="@{srcdir}">
     <exclude name="**/*.java" />
    </fileset>
   </copy>
  </sequential>
 </macrodef>
</project>

 

8、首先ant下面的init,然后运行compile-jsp,接着把build目录下面的src目录设置成Use as a source folder,最后运行compile-all

 

 

  • 大小: 103.8 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics