Categories
Tech Notes

Ant: Hello World in Ant

This is a simple reference of my, which might be helpful to someone after installing Ant and do some playing.

Use a text editor to create a file called build.xml:

<?xml version="1.0"?>
<project name="My Project" default="hello">
    <target name="hello">
       <echo>Hello World!</echo>

    </target>
  </project>

The first line in the file tells the system that this is an XML file. The next line tells ant that we have a project named “My Project” and that it has a default target called “hello”. Note that the file must always start with a <project> and end with a </project>. The central three lines are the one and only target in the file. They give the target a name and the target has just one task called “echo”

You can now open a shell and type “ant”. The default task is a required attribute of the project. Each target must have a name.

Output of Hello World

[root@nimal ant-tests]# ant
Buildfile: build.xml

hello:
     [echo] Hello World!

BUILD SUCCESSFUL
Total time: 1 second
[root@nimal ant-tests]# 

Variations

The following variations of echo will also give similar output.

<echo message="Hello There!"></echo>
<echo message="Hello There!"/>

2 replies on “Ant: Hello World in Ant”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s