在ant中删除文件

MHa*_*ris 5 java ant

为了便于访问,我在一系列项目文件夹的父级中有几个配置文件。在构建项目时,他们需要复制到项目源文件夹之一,直到构建完成后,然后我希望将它们删除。目前,我有这个:

<target name="build-java">
  <copy file="config.properties" todir="project/src" />
  <!-- Build other projects -->
  <delete file="project/src/config.properties" />
</target>
Run Code Online (Sandbox Code Playgroud)

如果项目建立,哪个工作。唉,我的骄傲,他们并不总是如此。理想情况下,我想要相当于以下 Java:

File src = new File("config.properties");
File dst = FileUtils.copyFile(src, "project/src");
dst.deleteOnExit();
// Carry on with the rest of the build, content in the knowledge that whatever happens, the file will die.
Run Code Online (Sandbox Code Playgroud)

但是CopyDelete ant 任务似乎都不能胜任这项工作。这似乎不是一个特别晦涩的需求?

Koo*_*obz 2

即使构建失败,您也可以尝试ant-contrib 的 trycatch来运行删除任务。

ant-contrib 中还有其他好东西,例如 foreach 任务。如果你能够安装它。