Menu
Ant > Ant Eclipse IDE Integration

Ant Eclipse IDE Integration

To integrate Ant build file with the Eclipse IDE, first create a build.xml file, right click the project select New->Other->XML, enter the name as build.xml and click Finish.


<?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.w3javaguide.helloworld.HelloWorld" classpath="build/classes" />
	</target>

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

To build the project right click the build.xml file and select Ant Build.

The HelloWorld.java file will be compiled and executed. The following message shows the sequence of events that happen once the build file is executed.


Buildfile: E:\Eclipse Workspace\AntExample\build.xml
clean:
   [delete] Deleting directory E:\Eclipse Workspace\AntExample\build
init:
    [mkdir] Created dir: E:\Eclipse Workspace\AntExample\build\classes
compile:
    [javac] Compiling 1 source file to E:\Eclipse Workspace\AntExample\build\classes
execute:
     [java] Hello World!
BUILD SUCCESSFUL
Total time: 625 milliseconds

You can download the build file here.

Build file :Download
Project :Download
Subscribe
Contact Us  |  Copyright © 2012 w3javaguide.com