Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command line to run the Ant task with hyphen in the task name

Tags:

ant

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 
like image 732
alex2k8 Avatar asked Nov 23 '10 14:11

alex2k8


People also ask

How do I run an Ant script from the command line?

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.

What is the Ant command?

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.

What is Taskdef in Ant?

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.

How do you list Ant targets?

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.


1 Answers

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. 
like image 118
Jim Avatar answered Sep 19 '22 15:09

Jim