Ant是一个Apache基金会下的跨平台的构件工具,它可以实现项目的自动构建和部署等功能。
一、解压ant安装包在D:\SWE下
二、环境变量配置
ANT_HOME D:\SWE\apache-ant-1.8.4
CLASSPATH ;%ANT_HOME%lib;
PATH ;%ANT_HOME%bin;
三、测试是否安装成功
在cmd命令方式下输入:ant -version
Ant安装与配置" title="Apache Ant安装与配置" action-data="http%3A%2F%2Fs3.sinaimg.cn%2Fmiddle%2F62ef85c24c4d9d4834dd2%26690" action-type="show-slide" style="margin: 0px; padding: 0px; border: 0px; list-style: none;" _src="http://pic.fxxz.com/up/2016-3/2016030810484799384.jpg">
出现问题:
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\
内容如下:
<?xml version="1.0" encoding="UTF-8" ?>
<project name="HelloWorld" default="run" basedir=".">
<property name="src" value="build/src" />
<property name="dest" value="build/classes" />
<property name="hello_jar" value="hello.jar" />
<property name="name" value="HelloWorld" />
<property name="version" value="1.0" />
<property name="year" value="2010" />
<echo message="----------- ${name} ${version} [${year}] ------------" />
<target name="init">
<echo message="mkdir ${dest}"></echo>
<mkdir dir="${dest}" />
</target>
<target name="compile" depends="init" description="Compile Java code">
<javac srcdir="${src}" destdir="${dest}" includeantruntime="on"/>
</target>
<target name="build" depends="compile">
<jar jarfile="build/${hello_jar}" basedir="${dest}"/>
</target>
<target name="run" depends="build">
<java classname="test.ant.HelloWorld" classpath="build/${hello_jar}"/>
</target>
<target name="clean">
<delete dir="${dest}" />
<delete file="${hello_jar}" />
</target>
</project>
运行:
Buildfile: D:\ant_home\apache-ant-1.8.1\bin\build.xml
[echo] ----------- HelloWorld 1.0 [2010] ------------
init:
[echo] mkdir build/classes
compile:
[javac] Compiling 1 source file to D:\ant_home\apache-ant-1.8.1\bin\build\classes
build:
[jar] Building jar: D:\ant_home\apache-ant-1.8.1\bin\build\hello.jar
run:
[java] Hello World
BUILD SUCCESSFUL
Total time: 1 second
检查在目录D:\ant_home\apache-ant-1.8.1\bin\build下生成hello.jar
140.5M / 09-05
76.4M / 03-25
55M / 06-05
237.9M / 04-13
900.9M / 03-02
96.2M / 07-06
311.2M / 07-06
335M / 07-06
200M / 07-06
413.8M / 07-06
484.7M / 09-27
165.4M / 09-05
353.9M / 06-05
131.8M / 04-13
195.6M / 03-03
45.6M / 09-08
665.2M / 07-06
2.84G / 07-06
93M / 07-06
338.3M / 07-06
1.38G / 07-26
488.3M / 07-16
109.8M / 06-03
142M / 01-08
1.2M / 11-23
548.8M / 04-13
1.6M / 04-13
1.48G / 03-18
646.6M / 03-03
133.7M / 03-03
110.5M / 09-05
33.4M / 09-05
325.8M / 08-12
60M / 04-29
254M / 04-25
659M / 04-23
1M / 12-26
253.4M / 12-08
253M / 12-08
1.19G / 11-16
369M / 09-22
181.5M / 09-22
201.2M / 09-05
488.3M / 07-16
248.9M / 12-08
248.9M / 12-08
100.6M / 03-06
148.9M / 03-06
1.12G / 07-06
1.25G / 07-06
1.76G / 09-22
1.92G / 04-17
116.2M / 04-10
201.5M / 04-13
7.31G / 07-01
94.3M / 07-06
2.48G / 07-06
7.63G / 07-06
1M / 07-06
778.1M / 07-06
561.8M / 07-11
72M / 07-06
548.7M / 07-06
1.00G / 07-06
9.13G / 07-06
126.2M / 07-06
72M / 07-06
105.1M / 07-06
132M / 07-06
132M / 07-06