A simple example for ANT BUILD

Posted: November 17, 2009 in Uncategorized
Tags: , , ,

Ant Build Sample Program

Assumptions
Workspace = d:\HelloWorldAnt
build.xml = d:\HelloWorldAnt\build.xml
HelloWorld.java = d:\HelloWorldAnt\src\HelloWorld.java

 

HelloWorld.java
public class HelloWorld {

public static void main(String[] args) {
System.out.println(“hello”);
}
}

build.xml
<project name=”HelloWorldAnt” basedir=”.” default=”main”>

<property name=”src.dir”     value=”src”/>

<property name=”build.dir”   value=”build”/>
<property name=”classes.dir” value=”${build.dir}/classes”/>
<property name=”jar.dir”     value=”${build.dir}/jar”/>

<property name=”main-class”  value=”HelloWorld”/>

<target name=”clean”>
<delete dir=”${build.dir}”/>
</target>

<target name=”compile”>
<mkdir dir=”${classes.dir}”/>
<javac srcdir=”${src.dir}” destdir=”${classes.dir}”/>
</target>

<target name=”jar” depends=”compile”>
<mkdir dir=”${jar.dir}”/>
<jar destfile=”${jar.dir}/${ant.project.name}.jar” basedir=”${classes.dir}”>
<manifest>
<attribute name=”Main-Class” value=”${main-class}”/>
</manifest>
</jar>
</target>

<target name=”run” depends=”jar”>
<java jar=”${jar.dir}/${ant.project.name}.jar” fork=”true”/>
</target>

<target name=”clean-build” depends=”clean,jar”/>

<target name=”main” depends=”clean,run”/>

</project>

Console

Buildfile: D:\Suhas\Workspaces\SuhasTryOuts\HelloWorldAnt\build.xml
clean:
[delete] Deleting directory D:\Suhas\Workspaces\SuhasTryOuts\HelloWorldAnt\build
compile:
[mkdir] Created dir: D:\Suhas\Workspaces\SuhasTryOuts\HelloWorldAnt\build\classes
[javac] Compiling 1 source file to D:\Suhas\Workspaces\SuhasTryOuts\HelloWorldAnt\build\classes
jar:
[mkdir] Created dir: D:\Suhas\Workspaces\SuhasTryOuts\HelloWorldAnt\build\jar
[jar] Building jar: D:\Suhas\Workspaces\SuhasTryOuts\HelloWorldAnt\build\jar\HelloWorldAnt.jar
run:
[java] hello
main:
BUILD SUCCESSFUL
Total time: 906 milliseconds

Advertisements
Comments

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 )

Google+ photo

You are commenting using your Google+ 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 )

w

Connecting to %s