Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Apache Ant is a Java-based command-line build tool: it reads an XML buildfile and runs the tasks you request. To understand a typical Ant build, start with four pieces: a project contains targets, targets group tasks and may depend on other targets, and properties supply reusable values such as directory paths.

How an Ant buildfile is organized

An Ant buildfile is XML. Its outer <project> element describes the build, and its <target> elements name units of work. A project can designate a default target; when you run Ant without naming a target, Ant runs that default.

Inside a target, tasks perform the actual work. The Apache Ant User Manual describes a task as “A task is a piece of code that can be executed.” Tasks can create directories, compile source files, package output, or remove generated files. A target is the named group and sequence that organizes those tasks; it is not itself a task.

How target dependencies control execution

A target can list prerequisite targets in its depends attribute. If you request a target, Ant runs its dependencies first, then the requested target. This lets a build express a sequence such as initialization, compilation, and packaging.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

depends sets execution order; it does not make the requesting target conditional on whether a dependency needed to run. If a dependency is listed, Ant schedules it as part of that target’s dependency sequence. Do not treat the attribute as an “only run this if necessary” test.

What properties do

Properties give names to values that can be reused in supported task attributes and text. A property named build, for example, can represent the compiled-output directory; refer to its value as ${build}. Property names are case-sensitive, so build and Build are different names.

You can also provide a property when starting Ant. For example, -Dbuild=build/classes sets the value of build from the command line. This is useful when you want to override a path without editing the buildfile.

A small buildfile, explained

This example follows a common beginner sequence: set paths, create the build directory, compile Java files, and package the compiled output into a JAR. It is an illustration, not a required layout for every Java project.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<project name="MyProject" default="dist" basedir=".">
  <property name="src" location="src"/>
  <property name="build" location="build"/>
  <property name="dist" location="dist"/>

  <target name="init">
    <mkdir dir="${build}"/>
  </target>

  <target name="compile" depends="init">
    <javac srcdir="${src}" destdir="${build}"/>
  </target>

  <target name="dist" depends="compile">
    <mkdir dir="${dist}/lib"/>
    <jar jarfile="${dist}/lib/MyProject.jar" basedir="${build}"/>
  </target>
</project>
  • project names the build, sets its base directory to the current directory, and makes dist the default target.
  • The three property elements define source, compiled-output, and distribution paths. With the project base directory set to ., these locations are relative to it.
  • init runs mkdir to create the build directory.
  • compile depends on init, so Ant creates the build directory before the javac task compiles sources from src into it.
  • dist depends on compile. It creates dist/lib and packages the compiled files into MyProject.jar.

To add a separate cleanup operation, define a target such as clean with a deletion task for generated directories. Keep cleanup separate from the default build unless you specifically want a build to remove output.

Install Ant and check your environment

Apache Ant 1.10.18, released September 6, 2026, is the latest release identified by Apache’s release page. The 1.10 line requires a Java 8 or later runtime. A JDK is needed to compile Java sources and to use many tasks; a JRE alone does not provide the full set of tools.

  1. Install a suitable Java environment. If you will compile Java sources, install a JDK.
  2. Download the Ant binary distribution from the Apache Ant download page and unpack it.
  3. Set ANT_HOME to the unpacked Ant directory and add its bin directory to PATH. You may set JAVA_HOME to the JDK installation directory.
  4. Open a new shell and run ant -version to check that Ant can be launched.

If running ant in a directory without a buildfile reports that it cannot find one, Ant may still have launched correctly; the error indicates that it did not find a buildfile to run in that directory. Classpath configuration is a frequent source of Ant problems, so do not add a global CLASSPATH as a default installation step.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Run a buildfile and choose what Ant runs

With no arguments, Ant looks for build.xml in the current directory and runs the project’s default target. In the example above, that target is dist.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • ant — find build.xml in the current directory and run the default target.
  • ant compile — run the target named compile and its dependencies.
  • ant -buildfile test.xml dist — use test.xml and request its dist target.
  • ant -buildfile test.xml -Dbuild=build/classes dist — use test.xml, set the build property from the command line, and request dist.

When reading an unfamiliar build.xml, find the project’s default target first, then trace the requested target’s depends values. Within each target, read its tasks in order and resolve property references such as ${build}. That gives you the execution path from command to output.

Check release-specific security guidance

Apache reports a path-traversal issue affecting Ant’s FTP and SCP tasks in versions before 1.10.18: a malicious server could write outside the intended download target directory. Apache lists the issue as fixed in 1.10.18. This warning is specific to those tasks; consult the Apache Ant security page for the advisory and current details.

Further reading

The Apache Ant User Manual is the primary reference for buildfile syntax, targets, tasks, properties, and command-line use. For the current release and installation requirements, see Apache’s release information and installation manual.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.