原貼地址:http://blog.sina.com.cn/s/blog_62ef85c201016e2n.html
下載Apache Ant 1.8.4http://ant.apache.org/bindownload.cgi
一、解壓ant安裝包在D:\SWE下
二、環境變量配置
ANT_HOME D:\SWE\apache-ant-1.8.4
CLASSPATH ;%ANT_HOME%lib;
PATH ;%ANT_HOME%bin;
三、測試是否安裝成功
在cmd命令方式下輸入:ant -versionApache
出現問題:
1)Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\lib
命令行敲ant命令後提示:“Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\lib”;ANT_HOME環境變量已經配置;
解決途徑:將“C:\Program Files\Java\jdk1.6.0_16\lib”目錄下的tools.jar文件拷貝到“C:\Program Files\Java\jre6\lib”目錄下,重新運行命令ant,運行正常,問題解決。
2)在cmd命令中:輸入ant,如果輸出: Buildfile:build.xml does not exist!
Build failed
說明ant安裝成功。
四、運行第一個ant腳本
在D:\ant_home\apache-ant-1.8.1\bin\下面新建目錄build,再在該目錄下新建目錄src
同時在src目錄下新建HelloWorld.java
內容如下:
package test.ant;
public class HelloWorld{
public static void main(String[] args){
System.out.println(“Hello World”);
}
};
編寫build.xml文件保存到D:\ant_home\apache-ant-1.8.1\bin\
內容如下: