• Zookeeper源代码编译为Eclipseproject(win7下Ant编译)


    为了深入学习ZooKeeper源代码,首先就想到将其导入到Eclispe中,所以要先将其编译为Eclispeproject。


    1、什么是Ant???

    Apache Ant™

    Apache Ant is a Java library and command-line tool whose mission is to drive processes described in build files as targets and extension points dependent upon each other. The main known usage of Ant is the build of Java applications. Ant supplies a number of built-in tasks allowing to compile, assemble, test and run Java applications. Ant can also be used effectively to build non Java applications, for instance C or C++ applications. More generally, Ant can be used to pilot any type of process which can be described in terms of targets and tasks.

    Ant is written in Java. Users of Ant can develop their own "antlibs" containing Ant tasks and types, and are offered a large number of ready-made commercial or open-source "antlibs".

    Ant is extremely flexible and does not impose coding conventions or directory layouts to the Java projects which adopt it as a build tool.

    Software development projects looking for a solution combining build tool and dependency management can use Ant in combination with Apache Ivy.

    The Apache Ant project is part of the Apache Software Foundation.


    Apache Ant,是一个将软件编译、測试、部署等步骤联系在一起加以自己主动化的一个工具,大多用于Java环境中的软件开发。由Apache软件基金会所提供。
    用过Linux系统的人都应该知道 make这个命令。当编译Linux内核及一些软件的源程序时,常常要用这个命令。Make命令事实上就 是一个项目管理工具。而Ant所实现功能与此类似。像make,gnumake和nmake这些编译工具都有 一定的缺陷,可是Ant却克服了这些工具的缺陷。最初Ant开发人员在开发跨平台的应用时,相同也 是基于这些缺陷对Ant做了更好的设计。

    Ant的核心是其构建文件,当開始一个新的项目时,首先应该编写Ant构建文件。

    构建文件定义了构建过程,并被团队开发 中每一个人使用。Ant构建文件默认名为build.xml。也能够取其它的名字。仅仅只是在执行的时候 把这个命名当作參数传给Ant。构建文件能够放在不论什么的位置。一般做法是放在项目顶层文件夹中。 这样能够保持项目的简洁和清晰。以下是一个典型的项目层次结构。
    (1) src存放文件。
    (2) class存放编译后的文件。
    (3) lib存放第三方JAR包。


    (4) dist存放打包,公布以后的代码。

    很多其它关于ant的知识大家能够自行搜索。


    2、安装ant

    (1)下载ant,我下载的是apache-ant-1.9.4-bin.zip(地址:http://ant.apache.org/bindownload.cgi

    (2)解压到特定文件夹,设置ANT_HOME(ant的解压路径)和path(%ANT_HOME%in)

    (3)打开cmd。执行ant -version。出现版本号信息说明成功安装了。


    3、下载Zookeeper源代码并用ant进行编译为eclipseproject

    Zookeeper GitHub的下载地址是:https://github.com/apache/zookeeper

    解压,打开cmd。切换到Zookeeper源代码的根文件夹以下(以下有一个build.xml文件),然后输入命令> ant eclipse

    出现以下界面提示编译成功:



    然后打开eclispe,随便什么版本号,选择import。类型是现有的eclispeproject。



    点击完毕。可是发现我的源代码居然有好几处错误。只是类型都是一样,都是Cannot switch on a value of type XXX:



    在网上查了一下,跟project文件使用来编译的JDK版本号有关,须要将jdk 7切换到jdk 6:

    在导入的Zookeeperproject上面点击右键-》properties-》Java Compiler,将compiler compliance level切换为1.6:



    这样错误就消失了,以下就能够開始进入真正的Zookeeper源代码之旅了。


  • 相关阅读:
    SQL查询版本信息语句
    一个简单的 分组 计算组内记录数占比的 语句
    MSSQL 判断表是否存在的两种方法
    兼容IEFireFoxChrome的背景音乐播放
    [C# 基础知识系列]专题二:委托的本质论
    [C# 基础知识系列]专题八: 深入理解泛型(二)
    [C# 基础知识系列]专题九: 深入理解泛型可变性
    [C# 基础知识系列]专题一:深入解析委托——C#中为什么要引入委托
    [C# 基础知识系列]专题六:泛型基础篇——为什么引入泛型
    [C# 基础知识系列]专题四:事件揭秘
  • 原文地址:https://www.cnblogs.com/gccbuaa/p/7081137.html
Copyright © 2020-2023  润新知