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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With