Home > Programming > Tip: How to see all available Ant targets

Tip: How to see all available Ant targets

June 18th, 2007

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.

Categories: Programming Tags:
  1. Nate
    June 19th, 2007 at 02:04 | #1

    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.

  2. Nate
    June 19th, 2007 at 02:07 | #2

    Ugh, html stripping took out my lovely fake tabs…
    That was ‘ant’ followed by tab tab. ‘ant c’ followed by tab.

  3. Sualeh Fatehi
    June 19th, 2007 at 10:27 | #3

    If you find yourself using this command often, you may want to use the abbreviation: ant -p

  4. June 19th, 2007 at 22:53 | #4

    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.

  5. June 20th, 2007 at 10:45 | #5

    >> 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]$

  6. June 20th, 2007 at 10:49 | #6

    [sara@notebookws114 Temp]$ cat build.xml

  7. June 20th, 2007 at 10:52 | #7

    One last time..

    [sara@notebookws114 Temp]$ cat build.xml
    <project>
    <target name=”no-desc”/>
    </project>

Comments are closed.