自己的build.xml
<?xml version="1.0" encoding="gb2312"?>
<project name="app" default="build" basedir=".">
<property name="app.name" value="hello-ant"/>
<property name="app.jar" value="${app.name}.jar"/>
<property name="app.copyright" value=" Copyright (c) 2005 The Robbie's Software Foundation. All rights reserved."/>
<property name="src.dir" location="src"/>
<property name="build.dir" location="build"/>
<property name="build.docs" value="${build.dir}/docs"/>
<property name="build.docs.api" value="${build.docs}/api"/>
<property name="dist.dir" location="dist"/>
<property name="lib.dir" location="lib"/>
<property environment="env"/> <!--取系l环境变?->
<path id="myclasspath">
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${env.STRUTS_HOME}">
<include name="lib/*.jar"/>
</fileset>
<!--
pathelement只能d单个的jar文g, 没有fileset方便
<pathelement path="${env.STRUTS_HOME}/lib/struts.jar"/>
-->
</path>
<target name="init" depends="clean">
<echo message="初始?.."/>
<mkdir dir="${build.dir}"/>
</target>
<target name="build" depends="init">
<echo message="~译?.."/>
<javac srcdir="${src.dir}" destdir="${build.dir}" verbose="true">
<classpath refid="myclasspath"/>
<compilerarg value="-Xlint:all"/> <!--|上找了半天才找到的, 用于djavac的编译参?->
</javac>
</target>
<target name="clean">
<echo message="清理?.."/>
<delete dir="${build.dir}"/>
<delete dir="${dist.dir}"/>
</target>
<target name="dist" depends="build">
<echo message="制作jar..."/>
<tstamp/>
<mkdir dir="${dist.dir}"/>
<jar destfile="${dist.dir}/app-${DSTAMP}${TSTAMP}.jar" basedir="${build.dir}"/>
</target>
<target name="javadocs" depends="dist">
<echo message="制作api手册..."/>
<mkdir dir="${build.docs.api}"/>
<javadoc packagenames="tax.*"
sourcepath="${src.dir}"
defaultexcludes="yes"
destdir="${build.docs.api}"
author="true"
version="true"
use="true"
windowtitle="Docs API">
<doctitle><![CDATA[<h1>tax struts ant API Docs</h1>]]></doctitle>
<bottom><![CDATA[<i>${app.copyright}</i>]]></bottom>
</javadoc>
</target>
</project>
别h的build.xml
<?xml version="1.0" encoding="GB2312" ?>
<!--
=======================================================================
hello-ant 目 ,学习ant工具的第2个build file.
参照ant的jakarta-ant-1.6alpha的build.xml
Copyright (c) 2002 The Neusoft Software Foundation. All rights
reserved.
=======================================================================
-->
<project default="dist" basedir=".">
<!--
===================================================================
定义属性(property tasksQ?br /> 最好把用到的\径呀Q名U呀都在q里定义成全局变量
例:定义
<property name="a" value="hello"/>
以后可以这L它:
<property name="b" value="${a}/b"/>
现在:b=="hello/b"
===================================================================
-->
<!--主要的系l环境属?->
<property environment="env"/><!--取window,unix...的环境变?->
<property name="java.home" value="${env.JAVA_HOME}"/>
<property name="ant.home" value="${env.ANT_HOME}"/>
<!--主要的app环境属?->
<property name="app.name" value="hello-ant"/>
<property name="app.jar" value="${app.name}.jar"/>
<property name="app.copyright" value=" Copyright (c) 2002 The Neusoft Software Foundation. All rights reserved."/>
<!--app中src的属?->
<property name="src.dir" value="src" />
<property name="src.main" value="${src.dir}/main"/>
<property name="src.script" value="${src.dir}/script"/>
<!--app用到的lib-->
<property name="lib.dir" value="lib"/>
<!--app的build目录?->
<property name="build.dir" value="build" />
<property name="build.classes" value="${build.dir}/classes"/>
<property name="build.docs" value="${build.dir}/docs"/>
<property name="build.docs.api" value="${build.docs}/api"/>
<property name="build.lib" value="${build.dir}/lib"/>
<!--app的dist (distribution) 目录?->
<property name="dist.dir" value="dist"/>
<property name="dist.bin" value="${dist.dir}/bin"/>
<property name="dist.docs" value="${dist.dir}/docs"/>
<property name="dist.lib" value="${dist.dir}/lib"/>
<!--app的docs目录?->
<property name="docs.dir" value="docs"/>
<!--
定义一l\径以后可以通过id重用q组路径 Q例Q?br /> <javac srcdir="src/main" destdir="build/classes">
<classpath refid="classpath"/>
</javac>
-->
<path id="classpath">
<!--本项目只有一个javaQ用不上classpathQ这里只是做个例?->
<pathelement location="${build.classes}"/>
<pathelement path="${java.home}/lib/tools.jar"/>
</path>
<!--
===================================================================
init 准备目录(File Tasks)
主要的目录结构通常是不会变的,一L成他?br /> ===================================================================
-->
<target name="init">
<!--清除以前目录-->
<delete dir="${build.dir}" failonerror="false" />
<delete dir="${dist.dir}" failonerror="false"/>
<!--准备目录-->
<mkdir dir="${build.dir}"/>
<mkdir dir="${build.classes}"/>
<mkdir dir="${build.docs}"/>
<mkdir dir="${build.docs.api}"/>
<mkdir dir="${build.lib}"/>
<mkdir dir="${dist.dir}"/>
<mkdir dir="${dist.bin}"/>
<mkdir dir="${dist.lib}"/>
</target>
<!--
===================================================================
Build the code (Compile Tasks,File Tasks)
===================================================================
-->
<target name="build" depends="init">
<!--~译-->
<javac srcdir="${src.main}" destdir="${build.classes}">
<classpath refid="classpath"/>
</javac>
</target>
<!--
===================================================================
打包文档(Archive Tasks)
Create the project jars: xxx1.jar and xxx2.jar
===================================================================
-->
<target name="jars" depends="build">
<jar basedir="${build.classes}" jarfile="${build.lib}/${app.jar}"/>
</target>
<!--
===================================================================
Creates the API documentation
===================================================================
-->
<target name="javadocs"
depends="jars"
description="--> creates the API documentation">
<!--copy docs 手册... -->
<copy todir="${build.docs}">
<fileset dir="${docs.dir}"/>
</copy>
<javadoc packagenames="hello.ant.*"
sourcepath="${src.main}"
defaultexcludes="yes"
destdir="${build.docs.api}"
author="true"
version="true"
use="true"
windowtitle="Docs API">
<doctitle><![CDATA[<h1>hello ant Docs API</h1>]]></doctitle>
<bottom><![CDATA[<i>${app.copyright}</i>]]></bottom>
<tag name="todo" scope="all" description="To do:" />
</javadoc>
</target>
<!--
===================================================================
Create the distribution that can run (Archive Tasks)
主要是从各目录中把该copy的copy?br /> ===================================================================
-->
<target name="dist" depends="javadocs">
<!--copy bin 执行文g -->
<copy todir="${dist.bin}">
<fileset dir="${src.script}/"/>
</copy>
<copy todir="${dist.docs}">
<fileset dir="${build.docs}/"/>
</copy>
<!-- copy lib 文g -->
<copy todir="${dist.lib}">
<fileset dir="${build.lib}/"/>
</copy>
</target>
<!--
===================================================================
Cleans everything(File Tasks)
例如可以删除build中的文gQ留l你发挥?br /> ===================================================================
-->
</project>

]]>