我有一个基本的ant脚本,我将一组文件复制到任何目标之外的目录中.然后,我想在任何/所有目标运行后清理这些文件,而不管依赖性如何.我遇到的主要问题是目标可能是’compile’或’de
<project name="proto" basedir=".." default="deploywar"> ... <copy todir="${web.dir}/WEB-INF/lib"> <fileset dir="${web.dir}/WEB-INF/lib/common"/> </copy> <target name="compile"> <!-- Uses ${web.dir}/WEB-INF/lib --> .... </target> <target name="clean" description="Clean output directories"> <!-- Does not use ${web.dir}/WEB-INF/lib --> .... </target> <target name="deploywar" depends="compile"> <!-- Uses ${web.dir}/WEB-INF/lib --> .... </target> <target name="cleanUpLib"> <!-- Clean up temporary lib files. --> <delete> <fileset dir="${web.dir}/WEB-INF/lib"> <include name="*.jar"/> </fileset> </delete> </target>要在任何/所有目标之后运行目标而不考虑依赖关系,您可以使用构建侦听器或一些try / catch / finally模式,有关详细信息,请参阅:
> https://stackoverflow.com/a/6391165/130683
> https://stackoverflow.com/a/1375833/130683