自己的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"/> <!--取系统环境变量-->
<path id="myclasspath">
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${env.STRUTS_HOME}">
<include name="lib/*.jar"/>
</fileset>
<!--
pathelement只能添加单个的jar文件, 没有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"/> <!--网上找了半天才找到的, 用于添加javac的编译参数-->
</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>
别人的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 tasks)
最好把用到的路径呀,名称呀都在这里定义成全局变量
例:定义
<property name="a" value="hello"/>
以后就可以这样用它:
<property name="b" value="${a}/b"/>
现在:b=="hello/b"
===================================================================
-->
<!--主要的系统环境属性-->
<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"/>
<!--
定义一组路径以后可以通过id重用这组路径 ,例:
<javac srcdir="src/main" destdir="build/classes">
<classpath refid="classpath"/>
</javac>
-->
<path id="classpath">
<!--本项目只有一个java,用不上classpath,这里只是做个例子-->
<pathelement location="${build.classes}"/>
<pathelement path="${java.home}/lib/tools.jar"/>
</path>
<!--
===================================================================
init 准备目录(File Tasks)
主要的目录结构通常是不会变的,一起生成他们
===================================================================
-->
<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上
===================================================================
-->
<target name="dist" depends="javadocs">
<!--copy bin 执行文件 -->
<copy todir="${dist.bin}">
<fileset dir="${src.script}/"/>
</copy>
<copy todir="${dist.docs}">
<fileset dir="${build.docs}/"/>
</copy>
<!-- copy lib 文件 -->
<copy todir="${dist.lib}">
<fileset dir="${build.lib}/"/>
</copy>
</target>
<!--
===================================================================
Cleans everything(File Tasks)
例如可以删除build中的文件,留给你发挥吧
===================================================================
-->
</project>