javac
: Compiles Java source files into bytecode.javadoc
: Generates API documentation from Java source files.depend
: Manages dependencies between Java classes and recompiles only the necessary files.rmic
: Generates stubs and skeletons for remote method invocation (RMI).mkdir
: Creates directories.delete
: Deletes files or directories.copy
: Copies files or directories.move
: Moves or renames files or directories.chmod
: Changes file permissions (Unix-based systems).tar
: Creates or extracts tar archives.zip
: Creates or extracts ZIP archives.unzip
: Extracts files from ZIP archives.gzip
: Compresses files using GZIP.gunzip
: Decompresses GZIP files.jar
: Creates or extracts JAR files.war
: Creates or extracts WAR (Web Application Archive) files.ear
: Creates or extracts EAR (Enterprise Application Archive) files.exec
: Executes a system command.java
: Runs a Java class.apply
: Executes a system command for a set of files.ant
: Calls another Ant build file.antcall
: Calls a target within the same build file.antversion
: Checks the version of Ant being used.condition
: Evaluates a condition and sets a property based on the result.property
: Sets or defines properties.propertyfile
: Manipulates Java property files.loadproperties
: Loads properties from a file.echoproperties
: Displays all properties.input
: Prompts the user for input.tstamp
: Sets properties with the current date and time.junit
: Runs JUnit tests.junitreport
: Generates HTML reports from JUnit test results.testng
: Runs TestNG tests.cvs
: Interacts with a CVS repository.svn
: Interacts with a Subversion repository (requires external libraries).git
: Interacts with a Git repository (requires external libraries).echo
: Outputs messages to the console or a file.mail
: Sends email notifications.xslt
: Applies XSLT transformations to XML files.style
: Applies XSLT stylesheets to XML files.sql
: Executes SQL statements against a database.replace
: Replaces text in files.concat
: Concatenates files.checksum
: Generates checksums for files.touch
: Updates the timestamp of a file or creates it if it doesn't exist.waitfor
: Waits for a specific condition to be met (e.g., file availability, network connectivity).<project name="MyProject" default="build" basedir="."> <!-- Set properties --> <property name="src.dir" value="src"/> <property name="build.dir" value="build"/> <property name="dist.dir" value="dist"/> <!-- Clean the build directory --> <target name="clean"> <delete dir=""/> <delete dir=""/> </target> <!-- Create directories --> <target name="init" depends="clean"> <mkdir dir=""/> <mkdir dir=""/> </target> <!-- Compile Java source files --> <target name="compile" depends="init"> <javac srcdir="" destdir=""/> </target> <!-- Create a JAR file --> <target name="jar" depends="compile"> <jar destfile="/MyProject.jar" basedir=""/> </target> <!-- Default target --> <target name="build" depends="jar"> <echo message="Build completed!"/> </target> </project>
build.xml
file.ant
:
build.xml
).ant
in your command line, Ant will look for a build.xml
file in the current directory and execute the default target defined within it.ant <target_name>
.build.xml
) to define the build process. These files contain targets, which are sequences of tasks.<javac>
for compiling Java code, <jar>
for creating JAR files).
ant
(executes the default target)ant compile
(executes the "compile" target)ant clean dist
(executes the "clean" and "dist" targets)ant -Dmy.property=value
(sets a property on the command line)ant -f mybuild.xml
(specifies a different build file)ANT_HOME
environment variable should be set to the Ant installation directory.ANT_HOME/bin
directory should be added to your system's PATH
environment variable.