java ant安裝與使用

來源:互聯網
上載者:User

ant是什麼好像很費話,反正很多開源項目都用ant.

我也必須的會用。首先是入門吧。

1,下載安裝

去apache官網下載一個ant,http://ant.apache.org/

:http://labs.mop.com/apache-mirror//ant/binaries/apache-ant-1.8.4-bin.zip

解壓後,設定環境變數(path)和ant_home(ANT_HOME)

path= %ANT_HOME%\bin;

開啟cmd,輸入如:ant -version:

會出現如下:

C:\Documents and Settings\Administrator>ant -version
Apache Ant(TM) version 1.8.4 compiled on May 22 2012

 

2,簡單的demo

建立java項目demo,建立類檔案。ANTDemo.java

輸入如下代碼:

1 package test;2 3 public class ANTDemo{4      public static void main(String[] args){5           System.out.println("this is ant demo!");6     }  7 }

在項目根目錄下面建立build.xml

 1 <?xml version="1.0" encoding="UTF-8"?> 2 <project name="demo" default="compile" basedir="."> 3     <property name="classdir" value="${basedir}/tempbuild/classes"/> 4      5     <target name="compile"> 6         <!-- create class temp folder --> 7         <mkdir dir="${classdir}"/> 8              9         <!-- java compile to classes -->10         <javac srcdir="${basedir}/src" destdir="${classdir}" includeantruntime="true">11             12         </javac>13         14         <!--run -->15         <java classname="test.ANTDemo">16             <classpath>17                 <pathelement path="${classdir}"/>18             </classpath>19         </java>20         21         <!-- package to jar -->22         <jar destfile="demo.jar" basedir="${classdir}">23             <manifest>24                 <attribute name="Main-class" value="ANTDemo"/>25             </manifest>26         </jar>27         28         <!-- delete temp dir -->29         <delete dir="${basedir}/tempbuild"/>30         31     </target>32     33 </project>

接下來就運行這個任務了。開啟cmd   輸入build檔案所在的路徑,

C:\Documents and Settings\Administrator>ant -file  E:/workspace/demo/build.xml

就可以看到結果了。並且在項目根目錄下面會看到,demo.jar

再就是ant的使用命令介紹了。

http://www.cnblogs.com/philander/articles/1782254.html

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.