Target can be seen as module of tasks in ant configuration file. We can request ant to execute specific target, by passing command line input. Each target may have one or more tasks. Following is sample buildConfig.xml
<?xml version="1.0"?>
<project name="AntDemo" default="hello">
<target name="hello">
<echo>Hello World - Welcome to Apache Ant!</echo>
</target>
<target name="stopOracle">
<exec executable="cmd">
<arg value="/c"/>
<arg value="net stop OracleServiceORCLDB"/>
</exec>
</target>
<target name="startOracle">
<exec executable="cmd">
<arg value="/c"/>
<arg value="net start OracleServiceORCLDB"/>
</exec>
</target>
<target name="deleteLogs" depends="stopOracle"
description="Clean output directories">
<delete>
<fileset dir="d:/logs">
<include name="**/*.class"/>
</fileset>
</delete>
</target>
<target name="compileSource">
<javac
srcdir="D:/Learning/11JAVA XML/1. javax.xml.bind/workspace/01HelloWorld/src"
destdir="D:/Learning/11JAVA XML/build/classes"/>
<jar destfile="D:/deployModule/lib/util.jar"
basedir="D:/Learning/11JAVA XML/build/classes"
includes="*"
>
</jar>
</target>
</project>
Exec as Target : please refer target named “stopOracle” having exec as task tag inside. It contains executable command to stop oracle service. if we pass this as target it will stop oracle databse service named “OracleServiceORCLDB”. Similarly we have “startOracle” to start the oracle database instance service.



Multiple Tasks : If we want two or more tasks to be executed together as single module, multiple tasks can be mentioned in single target. Target “compileSource” contains the two tasks compile .java files and also create the jar of compiled classes.
