Tutorials     About     RSS
Tech and Media Labs

Ant Tasks

Jakob Jenkov
Last update: 2018-03-24

Ant tasks are the units of your Ant build script that actually execute the build operations for your project. Ant tasks are usually embedded inside Ant targets. Thus, when you tell Ant to run a specific target it runs all Ant tasks nested inside that target.

Ant is shipped with a ton of built-in tasks for all kinds of build related operations. I won't get into detail with them all here. Many of them are already pretty well described in the official Ant manual (click the link, and then click the "Ant Tasks" link in the left side).

Some of the tasks you will see are:

  • mkdir
  • copy
  • delete
  • javac
  • javadoc
  • jar

To see an example of how these tasks are used, see the next tutorial in this trail: Ant Java build script example .

These few tasks are far from the total number of tasks that Ant comes with. Ant contains tasks for all kinds of exotic operations like zipping, unzipping, copying to remote servers via SSH (Secure Copy - SCP), running unit tests and much, much more. You should go explore the Ant task list in the official Ant manual.

Ant Task Example

Just so you can see how using an Ant task looks inside an Ant build script, here is an example Ant target with two Ant tasks inside:

<target name="compile" depends="init">
    <echo>Compiling Java source</echo>

    <javac classpathref="projectClasspath"
           destdir="${dir.build.classes}" />

This example defines an Ant target named compile which uses two Ant tasks inside: The echo Ant task and the javac Ant task (which compiles Java code).

The tasks listed inside an Ant target are executed in the sequence in which they are listed inside the Ant target. Thus, this target will first write a text to the command prompt and then run the Java compiler.

Jakob Jenkov

Featured Videos

Thread Congestion in Java - Video Tutorial

Sponsored Ads

Maildroppa - Smart Email Marketing Solution
Close TOC

All Trails

Trail TOC

Page TOC