Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant: How to execute a command for each file in directory?

I want to execute a command from an Ant buildfile, for each file in a directory.
I am looking for a platform-independent solution.

How do I do this?

Sure, I could write a script in some scripting language, but this would add further dependencies to the project.

like image 212
ivan_ivanovich_ivanoff Avatar asked Sep 23 '09 19:09

ivan_ivanovich_ivanoff


People also ask

How do you run ant commands?

To run the ant build file, open up command prompt and navigate to the folder, where the build. xml resides, and then type ant info. You could also type ant instead. Both will work,because info is the default target in the build file.

Which task is used to load the file into a property in ant?

This task is used to load file into a property. It works on files and provides a srcFile attribute for ease. It uses default encoding current locale unless other one is specified.

What is Ant build file?

Ant is a Java-based build tool created as part of the Apache open-source project. You can think of it as a Java version of make. Ant scripts have a structure and are written in XML. Similar to make, Ant targets can depend on other targets. For example, Ant is used in the context of plug-in development in the build.

What are ant commands?

It is the most complete Java build and deployment tool available. It is platform neutral and can handle platform specific properties, such as file separators. It can be used to perform platform specific tasks such as modifying the modified time of a file using 'touch' command. Ant scripts are written using plain XML.


1 Answers

Use the <apply> task.

It executes a command once for each file. Specify the files by means of filesets or any other resource. <apply> is built-in; no additional dependency needed; no custom task implementation needed.

It's also possible to run the command only once, appending all files as arguments in one go. Use the parallel attribute to switch the behaviour.

Sorry for being late a year.

like image 75
Alex Avatar answered Sep 28 '22 14:09

Alex