Explain how to start to use ANT and provide a "Hello World" ant script

Explain how to start to use Ant and provide a "Hello World" ANT script.

Before starting to use ANT, we should be clear about the project name and the .java files and most importantly, the path where the .class files are to be placed.

For example, we want the application HelloWorld to be used with ant. The Java source files are in a subdirectory called Dirhelloworld, and the .class files are to put into a sub directory called Helloworldclassfiles.

1. The build file by name build.xml is to be written. The script is as follows
<project name=”HelloWorld” default=”compiler” basedir=”.”>
<target name=”compiler”>
<mkdir dir = “Helloworldclassfiles”>
<javac srcdir=”Dirhelloworld” destdir=”Helloworldclassfiles”>
</target>
</project>

2. Now run the ant script to perform the compilation:
C :\> ant
Buildfile: build.xml

and see the results in the extra files and directory created:
c:\>dir Dirhelloworld
c:\>dir Helloworldclassfiles

All the .java files are in Dirhelloworld directory and all the corresponding .class are in Helloworldclassfiles directory.

Note: mkdir command is to be used in MS-DOS and mk dir command is to be used in UNIX/Linux.

Dir command is to be used in MS-DOS and ls command is to be used in UNIX /Linux.

Explain how to start to use Ant and provide a "Hello World" ant script.

<?xml version="1.0"?>

<project name="HelloWorld" default="compile" basedir=".">

<!-- set global properties for this build -->
<property name="src" value="." />
<property name="build" value="classes" />

<target name="init">
      <!-- Create the time stamp -->
<tstamp/>
</target>

<target name="compile" depends="init">
      <!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}" />
</target>
</project>

1. <project> element defines a project name, a default target, and a base directory.
2. init task serves only to create a project timestamp. It sets the DSTAMP, TSTAMP, and TODAY properties in the current project.
3. The actual compile target which depends on init. Before compile is executed, init executes in order to prepare the environment. Ant will attempt to execute the attribute targets, depending on the order they appear.
Explain how to set classpath in ANT
Explain how to set classpath in ANT - The following is the code snippet to set the classpath in ant:....
How does ANT read properties? How to set my property system?
How does ANT read properties? - Properties in ant are set in an order. Once a property is set, later the same property can not overwrite the previous one......
Explain how to modify properties in ANT
Explain how to modify properties in ANT - We can not modify the properties in ant. The properties in ant are immutable in nature...
Post your comment