The task name starts with a hyphen "-".
<?xml version="1.0" encoding="UTF-8"?> <project name="proj"> <target name="-task1"> <echo>Done!</echo> </target> </project>
How can I specify this task when running ant script from command line? This would not work:
ant -task1 -f test.xml
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.
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.
Description. Adds a task definition to the current project, such that this new task can be used in the current project. This task is a form of Typedef with the attributes adapter and adaptto set to the values org.
which you can then set as the default, so just typing ant will list the available targets. small suggestion. make "help" target as default. As a result running "ant" will invoke "help" target that will print all available targets.
Enclose the task name in quotes.
ant "-task1" -f test.xml
Update: From Ant docs
Targets beginning with a hyphen such as "-restart" are valid, and can be used to name targets that should not be called directly from the command line. For Ants main class every option starting with hyphen is an option for Ant itself and not a target. For that reason calling these target from command line is not possible. On the other hand IDEs usually don't use Ants main class as entry point and calling them from the IDE is usually possible.
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