Instead of a model extended with shell-based commands, Ant is extended using Java classes.Įach task is run by an object that implements a particular task interface.Īnt build files are written in XML (and have the default name build.xml).Įach build file contains one project and at least one (default) target.Įach task element of the build file can have an id attribute and can later be referred to by the value supplied to this. We can extend the same technology to build J2EE & other none-Java applications like C,C++ as well.At runtime, a user can specify which Ant target(s) they want to run, and Ant will generate and execute tasks from a dependency tree built from the target(s). There are many more targets offered by ANT for our ease. Here we tried to automate our Application building process using some basic targets of Apache ANT. We may create our ANT targets by extending the Task class from ANT and using the taskdef tag. The result of the test is directed to the report directory mentioned in the todir attribute of bachtest tag. Care should be taken while defining the class-path to include the compiled class-files. The fork attribute is used to run the test cases in a separate VM. The user may choose to halt or proceed with the build ,in case, the JUnit test cases fail using the haltonfailure attribute. The generated reports can be saved to a directory in the required format(plain txt, XML etc.) as shown in the above example. The ANT can be used to automatically, Unit test the Java Files. ANT properties files, follow the convention. The properties file can be included in the build.xml using the file attribute in the property tag. However, if the project is big, declaring build properties in a separate file is advisable. The properties are usually declared at the top of the build.xml file.
Version 1.7.1 of Ant, the Java-based build tool, is provided in the. It can be latter referred from the required targets using the refid attribute in the classpath tag. Apache Ant is installed to provides preconfigured build and deployment scripts. If you try to run an Ant build script inside of Eclipse, you will see this error: Could not find one or more classes: '.BuildException' I looked at the Ant configuration. Now Eclipse will use this version of ant instead of the built-in ant.
The compilation & some other targets may require availability of certain JAR files into the class-path. The class-path is set using the path tag & specifying the related JAR & class files. Download and unpack the latest ant build anywhere on your hard disk, then run Eclipse, and go to Window > Preferences > Ant > Runtime and click on the button called Ant Home Browse to the ant folder that you just unpacked, and choose that folder. Individual tasks can be run in isolation by double clicking only on the required task. We will discuss about build.properties in a while. The basedir ="." is used to mark the directory in which build.xml file is present, as the working directory.
The basedir ="." is used to mark the directory in which build.xml file is present as the working directory. The name attribute in the project tag is used to specify the name of the project.There can be multiple elements in a single project element.There is also a default attribute to the project element, which indicates the default task for the build file. The project is the root element in the build.xml.
The Build Fileis an XML file, which contains information about how to build a project. Apache Ant is a build tool with a long history in the Java world that is still widely used, albeit by a decreasing number of teams. Now that we are all set lets get going with some actual coding.