Tip: How to see all available Ant targets
If you have ever had to do a build where you weren’t sure what the right target was, then this simple little tip will help. Entering the following command:
$ ant -projecthelp
or, for those who like short cuts,
$ ant -p
will display a list of all public ant targets available in the default build.xml file. I find myself using this all the time. It is a lot easier then loading the entire file into a text editor to search for the target I want.
I have to add one small caveat though to the above tip. Ant considers a public target to be one with a description. If the description attribute is missing, you will not see the target listed in the output.
That’s a good one across the board. I also discovered on an earlier project that (at least with an Ubuntu setup), tab completion/searching of ant targets is available at the command line. ‘ant’ lists them out, ‘ant c’ will recommend ‘clean’, ‘compile’, etc. with successive tabs.
Ugh, html stripping took out my lovely fake tabs…
That was ‘ant’ followed by tab tab. ‘ant c’ followed by tab.
If you find yourself using this command often, you may want to use the abbreviation: ant -p
Thanks for the tips. I tried the tab-tab one and it even worked on Windows. I added the shorter version (ant -p) to my tip above.
>> I have to add one small caveat though to the above tip. Ant considers a public target to be one with a description. If the description attribute is missing, you will not see the target listed in the output.
Incorrect. Not true always…
[sara@notebookws114 Temp]$ ant -version
Apache Ant version 1.7.0 compiled on December 13 2006
[sara@notebookws114 Temp]$ cat build.xml
[sara@notebookws114 Temp]$ ant -p
Buildfile: build.xml
Main targets:
Other targets:
no-desc
[sara@notebookws114 Temp]$
[sara@notebookws114 Temp]$ cat build.xml
One last time..
[sara@notebookws114 Temp]$ cat build.xml
<project>
<target name=”no-desc”/>
</project>