Zookeeper源碼學習1:win7下Ant編譯Zookeeper源碼為Eclipse工程

來源:互聯網
上載者:User

標籤:des   style   blog   http   io   color   ar   os   使用   

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源碼之旅了!


Zookeeper源碼學習1:win7下Ant編譯Zookeeper源碼為Eclipse工程

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.