IntelliJ IDEA 2022.2 Help

Getting started with Ant

Ant is a flexible, platform-independent build tool from Apache Ant Project. IntelliJ IDEA integrates with Ant to provide a comprehensive build process, that includes compilation, packaging with the documentation and source code, committing to version control, and so on.

You can create a new project, or if you have an exising project, import it.

If you created a new project or you imported an existing project without Ant then you need to create an Ant Build file to use Ant as the build tool in your project.

Ant works with the XML build file. Normally, the name of the build file is build.xml. Build file describes the steps, or build targets, required to build a project. The root element of the build file is <project>. IntelliJ IDEA makes it possible to work with existing build files, create new build files from scratch, or generate them automatically.

Create Ant build file

  1. In the Project tool window, select the directory, where the build file should be created.

  2. Right-click the directory and from the context menu, select New | File (Alt+Insert).

  3. In the New File dialog, specify the name of the new file with the xml extension, for example, build.xml.

    IntelliJ IDEA detect an Ant build script and displays the appropriate notification. Click Add Ant build file in the notification.

    the Add Ant Build file notification

    As a result, IntelliJ IDEA enables the Ant tool window, adds build.xml to it and opens the new file in the editor.

  4. In build.xml, specify the build targets.

    You can use the path-like structures in the fileset or dirset directives.

    We recommend that you enter at least a root tag in the build.xml so the file can be recognized as a build file.

    .

  5. Add the build file to the project if you skipped the notification.

Ant build target

A build target is identified with a unique name and defines a procedure that should be executed to accomplish a certain task, for example, create a JAR file, or generate API documentation. A target specified in the default attribute of the <project> element is considered the default target, which is executed when no other target is specified. This target is called the primary target, and is marked with bold font in the Ant Build tool window.

Path-like structures

IntelliJ IDEA enables using path-like structures in the task definitions. If a classpath is defined as a path-like structure, the paths in the fileset and dirset directives are resolved into the actual files and directories on the disk. All JARs, required for performing the task, should be placed to the same place that contains the JAR with task definitions.

Last modified: 09 September 2022