Ant的使用
1、下载安装下载:http://ant.apache.org需要设置的环境变量:
ANT_HOME:ant的安装目录
JAVA_HOME:jdk的安装目录
PATH:把%ANT_HOME%\bin目录加到path变量,以便于从命令行下直接运行ant
假定ant解压在c:\ant jdk装d:\j2sdk1.4.0
则在命令行下执行以下命令:
set ANT_HOME=c:\ant
set JAVA_HOME=D:\j2sdk1.4.0
set PATH=%PATH%;c:\ant\bin 2、工程文件目录结构:
一个ant 工程目录结构:
C:\workspace\ant.test:工程主目录
\src :源程序目录
\build\classes :编译后的 class 文件目录
\lib :开发工程所需要的类库目录,比如开发数据库时所需要的 jdbc lib(这次没用到)
\jar :打包好的 jar 程序目录(这次没用到)
\build.xml :工程配置文件\build.propertiees:工程资源文件
2、建立工程描述文件和建立工程资源文件
建立工程描述文件build.xml
<?xml version=&quot;1.0&quot;?>
<project default=&quot;main&quot; basedir=&quot;.&quot;>
<echo message=&quot;pulling in property files&quot; />
<property file=&quot;build.properties&quot; />
<target name=&quot;init&quot;>
<echo message=&quot;init. delete the old class files. and create the new folds.&quot; />
<delete dir=&quot;${classpath}&quot; />
<mkdir dir=&quot;${classpath}&quot; />
</target>
<target name=&quot;compile&quot; depends=&quot;init&quot;>
<echo message=&quot;compile the java source files.&quot; />
<javac srcdir=&quot;src\hello\ant&quot; destdir=&quot;${classpath}&quot; />
</target>
<target name=&quot;main&quot; depends=&quot;compile&quot;>
<echo message=&quot;calling java to run this java project.&quot; />
<java classname=&quot;hello.ant.HelloAnt&quot;>
<classpath>
<pathelement path=&quot;${classpath}&quot; />
</classpath>
</java>
</target>
</project> 建立工程资源文件:build.properties
文件内容是下面一行内容:
classpath=build\\classes
4、建立java源文件:hello.ant.HelloAnt.java
package hello.ant;
public class HelloAnt {
public static void main(String[] args) {
System.out.println(&quot;hello ant, the first time using ant... it is great.&quot;);
}
}
5、编译:
C:\workspace\ant.test>ant -buildfile build.xml
Buildfile: build.xml
pulling in property files
init:
init. delete the old class files. and create the new folds.
Deleting directory C:\workspace\ant.test\build\classes
Created dir: C:\workspace\ant.test\build\classes
compile:
compile the java source files.
Compiling 1 source file to C:\workspace\ant.test\build\classes
main:
calling java to run this java project.
hello ant, the first time using ant... it is great.
BUILD SUCCESSFUL
Total time: 890 milliseconds
C:\workspace\ant.test>
页:
[1]