写的第一个ant完整实例,可以正常运行,但还有些地方不太明白。
<?
xml version="1.0" encoding="UTF-8"
?>
<!-- name:对应工程的名字;default:需要的缺省任务(运行"ant"不指明任务时执行的任务) -->
< project name ="ZZ" default ="dist" basedir ="." >
<!-- 建立目录结构
src JAVA源码编辑目录
lib jar包(类库)存放目录
classes 编译生成的class文件存放目录
WebRoot jsp文件存放地方
-->
< property name ="src.dir" value ="src" />
< property name ="webapps.dir" value ="D:/Tomcat6.0/webapps/ZZ" />
< property name ="lib.dir" value ="${webapps.dir}/WEB-INF/lib" />
< property name ="classes.dir" value ="${webapps.dir}/WEB-INF/classes" />
< property name ="webroot.dir" value ="WebRoot" />
<!-- Compilation Classpath 路径设置 -->
< path id ="compile.classpath" >
< pathelement location ="${classes.dir}" />
< fileset dir ="${webroot.dir}/WEB-INF/lib" includes ="**/*.jar" />
</ path >
<!-- Clean Target 删除tomcat的目录结构 -->
< target name ="clean" description ="Delete old build and dist directories" >
< delete dir ="${webapps.dir}" />
</ target >
<!-- Prepare Target 建立打包的目的目录结构 -->
< target name ="prepare" >
< mkdir dir ="${classes.dir}" />
< mkdir dir ="${lib.dir}" />
</ target >
<!-- Compile Target 编译代码,在这之前先由prepare建立目录结构 -->
< target name ="compile" depends ="prepare" description ="Compile java sources" >
<!-- 不知道为什么不能删除copy部分,删除就不能成功编译类文件,难道我设置的path没有一点作用吗? -->
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
< copy todir ="${webapps.dir}" >
< fileset dir ="${webroot.dir}" >
< include name ="**/**" />
</ fileset >
</ copy >
< copy todir ="${lib.dir}" >
< fileset dir ="${webroot.dir}/WEB-INF/lib" >
< include name ="**/*.jar" />
</ fileset >
</ copy >
< copy todir ="${classes.dir}" >
< fileset dir ="${src.dir}" >
< include name ="**/*.xml" />
< include name ="**/*.properties" />
</ fileset >
</ copy >
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<!-- Compile java class as necessary -->
< javac srcdir ="${src.dir}" destdir ="${classes.dir}" debug ="true" >
<!-- @@@@@@@@@@@@@@@ 引用的path没有发挥作用 @@@@@@@@@@@@@@@@@ -->
< classpath refid ="compile.classpath" />
<!-- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -->
</ javac >
</ target >
<!-- Deploy Target 在tomcat下建立应用目录并部署应用 -->
< target name ="deploy" depends ="compile" description ="Deploy application to servlet container" >
<!-- Copy the contents of the build directory -->
< copy todir ="${webapps.dir}" >
< fileset dir ="${webroot.dir}" >
< include name ="**/**" />
</ fileset >
</ copy >
< copy todir ="${lib.dir}" >
< fileset dir ="${webroot.dir}/WEB-INF/lib" >
< include name ="**/*.jar" />
</ fileset >
</ copy >
< copy todir ="${classes.dir}" >
< fileset dir ="${src.dir}" >
< include name ="**/*.xml" />
< include name ="**/*.properties" />
</ fileset >
</ copy >
</ target >
<!-- Dist Target 将应用打包成war,在这之前先执行deploy -->
< target name ="dist" depends ="clean,deploy" description ="Create binary destribution" >
< jar jarfile ="ZZ.war" basedir ="${webapps.dir}" />
</ target >
</ project >
<!-- name:对应工程的名字;default:需要的缺省任务(运行"ant"不指明任务时执行的任务) -->
< project name ="ZZ" default ="dist" basedir ="." >
<!-- 建立目录结构
src JAVA源码编辑目录
lib jar包(类库)存放目录
classes 编译生成的class文件存放目录
WebRoot jsp文件存放地方
-->
< property name ="src.dir" value ="src" />
< property name ="webapps.dir" value ="D:/Tomcat6.0/webapps/ZZ" />
< property name ="lib.dir" value ="${webapps.dir}/WEB-INF/lib" />
< property name ="classes.dir" value ="${webapps.dir}/WEB-INF/classes" />
< property name ="webroot.dir" value ="WebRoot" />
<!-- Compilation Classpath 路径设置 -->
< path id ="compile.classpath" >
< pathelement location ="${classes.dir}" />
< fileset dir ="${webroot.dir}/WEB-INF/lib" includes ="**/*.jar" />
</ path >
<!-- Clean Target 删除tomcat的目录结构 -->
< target name ="clean" description ="Delete old build and dist directories" >
< delete dir ="${webapps.dir}" />
</ target >
<!-- Prepare Target 建立打包的目的目录结构 -->
< target name ="prepare" >
< mkdir dir ="${classes.dir}" />
< mkdir dir ="${lib.dir}" />
</ target >
<!-- Compile Target 编译代码,在这之前先由prepare建立目录结构 -->
< target name ="compile" depends ="prepare" description ="Compile java sources" >
<!-- 不知道为什么不能删除copy部分,删除就不能成功编译类文件,难道我设置的path没有一点作用吗? -->
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
< copy todir ="${webapps.dir}" >
< fileset dir ="${webroot.dir}" >
< include name ="**/**" />
</ fileset >
</ copy >
< copy todir ="${lib.dir}" >
< fileset dir ="${webroot.dir}/WEB-INF/lib" >
< include name ="**/*.jar" />
</ fileset >
</ copy >
< copy todir ="${classes.dir}" >
< fileset dir ="${src.dir}" >
< include name ="**/*.xml" />
< include name ="**/*.properties" />
</ fileset >
</ copy >
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<!-- Compile java class as necessary -->
< javac srcdir ="${src.dir}" destdir ="${classes.dir}" debug ="true" >
<!-- @@@@@@@@@@@@@@@ 引用的path没有发挥作用 @@@@@@@@@@@@@@@@@ -->
< classpath refid ="compile.classpath" />
<!-- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -->
</ javac >
</ target >
<!-- Deploy Target 在tomcat下建立应用目录并部署应用 -->
< target name ="deploy" depends ="compile" description ="Deploy application to servlet container" >
<!-- Copy the contents of the build directory -->
< copy todir ="${webapps.dir}" >
< fileset dir ="${webroot.dir}" >
< include name ="**/**" />
</ fileset >
</ copy >
< copy todir ="${lib.dir}" >
< fileset dir ="${webroot.dir}/WEB-INF/lib" >
< include name ="**/*.jar" />
</ fileset >
</ copy >
< copy todir ="${classes.dir}" >
< fileset dir ="${src.dir}" >
< include name ="**/*.xml" />
< include name ="**/*.properties" />
</ fileset >
</ copy >
</ target >
<!-- Dist Target 将应用打包成war,在这之前先执行deploy -->
< target name ="dist" depends ="clean,deploy" description ="Create binary destribution" >
< jar jarfile ="ZZ.war" basedir ="${webapps.dir}" />
</ target >
</ project >