Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting a file in ant

Tags:

java

ant

For ease of access, I have a couple of config files in the parent of a series of project folders. When building the projects, they need copying into one of the projects source folders until after the build is finished, whereupon I'd like them to be deleted. At the moment, I have this:

<target name="build-java">
  <copy file="config.properties" todir="project/src" />
  <!-- Build other projects -->
  <delete file="project/src/config.properties" />
</target>

Which does the job if the projects build. Alas for my pride, they don't always. Ideally, I'd like the equivalent of the following 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.

But neither the Copy nor the Delete ant tasks seem up to the job. This doesn't seem like a particularly obscure need?

like image 673
MHarris Avatar asked Feb 05 '10 09:02

MHarris


People also ask

How do I delete a file using SSH?

SSH command for deleting a folder/file To delete a file or a directory, use the command, rm.

How do I delete a directory file?

To remove a directory and all its contents, including any subdirectories and files, use the rm command with the recursive option, -r . Directories that are removed with the rmdir command cannot be recovered, nor can directories and their contents removed with the rm -r command.

How do I delete a file in Apache?

Deleting a fileRight-click on the file name to display a context menu. Click Delete, and you will get a confirmation dialog.


2 Answers

How about defining a "clean" task that deletes the leftover files, and you can call that after each build (even after failed builds)?

I think Ant is not very good with these kind of conditional flow-control things. There may be a way to make that work, but that could get messy,

like image 193
Thilo Avatar answered Sep 30 '22 15:09

Thilo


You could try ant-contrib's trycatch to run the delete task even if the build fails.

There's other goodies in ant-contrib like the foreach task. If you're able to install it.

like image 21
Koobz Avatar answered Sep 30 '22 15:09

Koobz