现在的位置: 首页 > 综合 > 正文

Zookeeper源码编译为Eclipse工程(win7下Ant编译)

2018年04月08日 ⁄ 综合 ⁄ 共 2107字 ⁄ 字号 评论关闭

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


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%\bin)

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

3、下载Zookeeper源码并用ant进行编译为eclipse工程

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

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

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

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

点击完成,但是发现我的源码竟然有好几处错误,不过类型都是一样,都是Cannot switch on a value of type XXX:


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

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

这样错误就消失了,下面就可以开始进入真正的Zookeeper源码之旅了!

抱歉!评论已关闭.