http://ant.apache.org/manual/index.html ANT常用任务
设置classpath
<path id="project.classpath">
<!-- 第1种方式 -->
<pathelement path="${basedir}/lib/aa.jar" />
<!-- 第2种方式 与1的区别在于location可以去当前路径,当然可以使用绝对路径-->
<pathelement location="aa.jar" />
<!-- 第3种方式 -->
<filelist id="file" dir="${basedir}/lib"><file name="a.jar" />
<file name="d:lib/b.jar" />
</filelist>
<!-- 第4种方式 -->
<fileset dir="d:/lib">
<include name="**/*.jar" />
</fileset>
</path>
使用classpath
<javac scdir="./src" destdir="./classes">
<classpath refid="project.classpath" />
</javac>
拷贝文件
拷贝一个文件
<copy file="myfile.txt" tofile="mycopy.txt" />
拷贝文件到目录
<copy file="myfile.txt" todir="../some/other/dir" />
拷贝目录到另一目录
<copy todir="../new/dir">
<fileset dir="sir_dir" />
</copy>
拷贝文件集合到目录
<copy todir="../dest/dir">
<fileset dir="src_dir">
<exclude name="**/*.java" />
</fileset>
</copy>
<copy todir="../dest/dir">
<fileset dir="src_dir" excludes="**/*.java" />
</copy>
删除文件,目录
<delete file="/lib/ant.jar" />
<delete dir="lib" />
<delete>
<fileset dir="." includes="**/*.bak" />
</delete>
移动文件,目录
<move todir="some/new/dir">
<fileset dir="my/src/dir">
<include name="**/*.jar" />
<exclude name="**/ant.jar" />
</fileset>
</move>
创建文件,目录
<touch file="myfile" />
<mkdir dir="${dist}/lib" />
设置property 读取环境变量
<property environment="env" />
读取属性文件中的属性
<property file="foo.peoperties" />
设置属性name-value
<property name="foo.dist" value="dist" />
读取文件中的属性配置
<property resource="foo.properties" />
jar包
<jar destfile="${dist}/lib/app.jar" basedir="{build}/classes"
includes="mypackage/test/**" excludes="**/Test.class" />
Ear包
<ear destfile="build/myapp.ear" appxml="src/metadata/application.xml">
<fileset dir="build" includes="*.jar,*.war" />
</ear>
执行程序
<target name="help">
<exec executable="cmd">
<arg value="/c" />
<arg value="ant.bat" />
<arg value="-p" />
</exec>
</target>
运行jar包
<java classname="test.Main">
<arg value="-h" />
<classpath>
<pathelement location="dist/test.jar" />
</classpath>
</java>
编译程序
<javac srcdir="${src}" destdir="${build}" classpath="xyz.jar" debug="on" source="1.4" />