Ant is free and open source build tool, written in Java, helps in automating the entire build process of a Java development project.
- Ant uses XML build files.
- By default, Ant looks for a build file named build.xml.
- The build file contains information about how to build a particular project.
- Each project contains multiple targets like creating directory, compiling source codes.
- Target can depend on other targets.
- Targets contain tasks.
- Behind each task is a Java class that performs the described work.
To install Ant follow the steps given below.
- Download the latest Ant distribution.
- Extract it (my location is E:\apache-ant-1.N)
- Set the following system variables
- ANT_HOME =E:\apache-ant-1.N
- PATH = %ANT_HOME%\bin
To make sure the installation is proper, go to command prompt and execute the command "ant - version", you will see the installed ant version.
In this example you will see how to compile a java program and compress it into a .jar file using Ant build file. The following listing shows the build.xml file.
01. <? xml version = "1.0" ?> 02. < project name = "Hello World" default = "compress" > 03. 04. < target name = "compile" > 05. < javac srcdir = "." /> 06. < echo > Compilation Complete! </ echo > 07. </ target > 08. 09. < target name = "compress" depends = "compile" > 10. < jar destfile = "HelloWorld.jar" basedir = "." includes = "*.class" /> 11. < echo > Building .jar file Complete! </ echo > 12. </ target > 13. 14. </ project >
To run the build.xml file, open the command prompt, go to the example directory, type the command "ant". You will see the following information.
|