Tuesday, June 27th, 2017

Ant

1

What is Ant ?

Ant is an open-source Java-based build tool from the Apache Software Foundation. Ant uses build files, which are simply XML files that tell the Ant program what to do.

Why Ant ?

1)  Simple syntax and easy to learn(If you know XML before).

2) Easy to use.

3)  Cross-platform.

4)   Built-in support for J2EE development, such as EJB compilation and      packaging.

5)  Automated deployment

How to install Ant ?

Get the binary release and set ANT_HOME and JAVA_HOME   environment variables.

Configure the PATH environment variable to point ant/bin directory.

Creating Build file

Example of a build file called build.xml

<?xml version=“1.0”>

<project name=“firstbuild” default=“compile” >

<target name=“compile”>

<javac srcdir=“.” />

<echo>compilation complete!</echo>

</target>

</project>

Project:

The <project> tag is the root element in the build file

The <project> tag has three attributes as follows:

  • name
  • default
  • basedir
  • Name – The name attribute gives the project a name and its valuable for the purpose of identifying log outputs.
  • Default – The default attribute refers to a target name within the build file.
  • Basedir – The basedir attribute defines the root directory of a project.

Targets:

A <target> is a single stage in the Build file.

The target compiles a set of files and package them into a JAR file.

A build file can have many targets but each should have unique name.

In the last example, the build file compile target contains two XML elements

  • <javac> (Java Compiler to compile the java code)
  • <echo> (To echoes a message to the screen)

Example of a Target:

//This target will compile the source code

<target name=“build-lib”>

<javac srcdir=“${src.ejb.dir}:${src.java.dir}”

destdir=“${build.dir}”

debug=“on”

deprecation=“on”

includes=“**/*.java”

excludes=“${global.exclude}”>

<classpath path=“${classpath.compile}” />

</javac>

</target>

//This target will package the jar file

<target name=“package-lib”>

<jar jarfile=“${dist}/lib/lib.jar” basedir=“${build.dir}” />

</target>

Tasks:

Tasks are the smallest building blocks of a build file and they performs following works,

  • Compiling Source Code
  • Packaging Classes
  • Retrieving file revisions from CVS
  • Copying files or directories

//To copy all the files from source in the projects www source directory to the dest directory to system’s weblogic installation

<copy todir=“${weblogic.dir}/${weblogic.server.home}/public_html/source ”>

<fileset dir=“${src.www.dir}/dest ”/>

</copy>

Happy Learning !!!

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • RSS
  • Technorati
  • Twitter

Comments

One Response to “Ant”

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

Secure Linux Web Hosting