Apache Ant - SPLessons

ANT Eclipse

Chapter 13

SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

ANT Eclipse

ANT Eclipse

shape Introduction

ANT projects can be run using Eclipse. Eclipse is an Integrated Development Environment, which gives workspace and provides various plug-ins to customize the environment.

shape Description

To work with ANT Eclipse, one should download it by clicking the below link.

Download and Installing Eclipse

shape Step-1

To include targets using FTP and to upload files to the remote server, some additional jar files are required such as:

Commons-net-*.jar
Jakarta-oro-*.jar

shape Step-2

Now, copy the jar file in lib folder in Eclipse. The folder will be as follows:
C:\Program Files\Eclipse\plugins\org.apache.ant_1.9.4\lib

shape Step-3

Then, go to

Window -> Preferences -> Ant -> Classpath -> Ant Home Entries -> Add External JAR’s -> select the two jar files in Lib folder.

shape Step-4

Integrating with eclipse can be done as follows.

Create a project as AntExample. Right click on the project and

New -> Other -> XML -> Enter build.xml -> Finish

Build the structure as shown below.

Now build.xml will be as follows

<?xml version="1.0" ?> 
<project name="Ant Example" default="execute">

	<target name="init" depends="clean">
		<mkdir dir="build/classes" />
	</target>

	<target name="compile" depends="init">
		<javac srcdir="src" destdir="build/classes" />
	</target>
	
	<target name="execute" depends="compile">
		<java classname="com.splessons.helloworld.HelloWorld" classpath="build/classes" />
	</target>

	<target name="clean">
		<delete dir="build" />
	</target>
	
</project>

HelloWorld.java

package com.splessons.helloworld;

public class HelloWorld {

	public static void main(String[] args) {
		System.out.println("Hello World!");
	}

}

shape Step-5

To build a project, right click on build.xml and click on Ant Buildas shown below.

If the build is successful, the following output will appear:

hello:
     [echo] Hello World!
BUILD SUCCESSFUL
Total time: 337 milliseconds

Summary

shape Key Points

  • IDE stands for Integrated Development Environment.
  • External jar files are to be set in Ant Classpath.