说来话长。它就是一个工程管理工具,比如一个最简单的hello world程序吧。第一步:写程序(不说了吧)第二步:写build.xml文件。如下:<project name="MyProject" default="dist" basedir="."> <!-- set global properties for this build -->
<property name="src" value="."/>
<property name="build" value="build"/>
<property name="dist" value="dist"/> <target name="init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
</target> <target name="compile" depends="init">
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}"/>
</target> <target name="dist" depends="compile">
<!-- Create the distribution directory -->
<mkdir dir="${dist}/lib"/> <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/lib/MyProject.jar" basedir="${build}"/>
</target> <target name="clean">
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>
</project>
第三步:ant 一下,然后会生成如下文件:
G:\SHARE\ant_test_prj\dist\lib\MyProject.jar这里的屏幕输出如下:
G:\SHARE\ant_test_prj>ant
Buildfile: build.xmlinit:compile:dist:BUILD SUCCESSFULTotal time: 1 second
G:\SHARE\ant_test_prj>
<property name="src" value="."/>
<property name="build" value="build"/>
<property name="dist" value="dist"/> <target name="init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
</target> <target name="compile" depends="init">
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}"/>
</target> <target name="dist" depends="compile">
<!-- Create the distribution directory -->
<mkdir dir="${dist}/lib"/> <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/lib/MyProject.jar" basedir="${build}"/>
</target> <target name="clean">
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>
</project>
第三步:ant 一下,然后会生成如下文件:
G:\SHARE\ant_test_prj\dist\lib\MyProject.jar这里的屏幕输出如下:
G:\SHARE\ant_test_prj>ant
Buildfile: build.xmlinit:compile:dist:BUILD SUCCESSFULTotal time: 1 second
G:\SHARE\ant_test_prj>
你安装了ant,就可以看一下他的document了,里面说得很详细了,我一下也说不清也说不完而且我也不是了解的非常多,常用的几个而已。象上面的:
<!-- set global properties for this build -->
<property name="src" value="."/>
<property name="build" value="build"/>
<property name="dist" value="dist"/>应该好理解,声明一下源文件所在目录是当前目录,编译目录是build,输出目录是dist,然后初始化
<target name="init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
</target>创建了编译路径。就开始compile了 <target name="compile" depends="init">
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}"/>
</target>调用javac来实现,源文件在变量${src}指的目录下。然后创建输出目录,并打包.class文件到输出目录下
<target name="dist" depends="compile">
<!-- Create the distribution directory -->
<mkdir dir="${dist}/lib"/> <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/lib/MyProject.jar" basedir="${build}"/>
</target>差不多就这样了,你还是自已理解一下吧。