Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML
 
 
Search All Tutorials

 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 
Jboss
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

10 Minutes Guide to Ant

                         

Introduction

Well for the next 10 minutes get ready to devote to the ant guide. This will make some sence to the ant.

Ant is a free tool under GNU Licence and is freely available at http://jakarta.apache.org/ant/ , current version of ant is 1.4.1. Ant allows the developer to automate the repeated process involved in the development of J2EE application. Developers can easily write the script to automate the build process like compilation, archiving and deployment.

For this tutorial I am using 1.4.1 and jdk1.4. I am also using Jboss 3.0 (with tomcat) downloaded from http://www.apache.org to deploy and test J2EE application developed in this lesson. In order to understand this tutorial you should have a solid knowledge of java programming and development of web application using java technologies.

Lesson 1

Downloading and Installing Ant

Before installing Ant make sure you have JDK1.3 or above installed on your machine.

For this tutorial download ant from http://jakarta.apache.org/ant/  and unzip the file into your favorite directory.

Set the class path to the bin directory of the ant.

Let's assume that Ant is installed in c:\ant\. The following code has to be put into autoexec.bat file:

set ANT_HOME=c:\ant
set JAVA_HOME=c:\jdk1.3
set PATH=%PATH%;%ANT_HOME%\bin

Testing Ant

Go to command prompt and issue the following command.

 
C:\anttest>Ant

Buildfile: build.xml does not exist!Build failed

C:\anttest>
  

If every this is installed correctly Ant will give the above message.

Now its time to do some work with Ant.

Ant uses configuration file called build.xml to work. This is the file where you defines the process of compiling, building and deploying.

Writing build.xml file

build.xml is a xml file used by ant utility to compile, build and deploy or run the application.

Now here is code of simple build.xml file which compiles a java file present in src directory and places compiled class file in build/src directory.

 
<?xml version="1.0"?>

<!-- Build file for our first application -->

<project name="Ant test project" default="build" basedir=".">

<target name="build" >

<javac srcdir="src" destdir="build/src" debug="true"

includes="**/*.java"

/>

</target>

</project>
    

First line of the build.xml file represents the document type declaration.  Next line is comment entry. Third line is the project tag. Each buildfile contains one project tag and all the instruction are written in the project tag.

The project tag:

<project name="Ant test project" default="build" basedir=".">

requires three attributes namely name, default and basedir.

Here is the description of the attributes:

Attribute Description
name Represents the name of the project.
default Name of the default target to use when no target is supplied.
basedir Name of the base directory from which all path calculations are done. 

All the attributes are required.

One project may contain one or more targets. In this example there is only one target.

<target name="build" >

<javac srcdir="src" destdir="build/src" debug="true"

includes="**/*.java"

/>

</target>

Which uses task javac to compile the java files.

Here is the code of our test1.java file which is to be compiled by the Ant utility.

 
class test1{

public static void main (String args[]){

System.out.println("This is example 1");

}

}

  

Download the code of this tutorial and unzip it in c:\. files will be unzipped in anttest directory. To run the Ant utility to compile the file go to c:\anttest\example1 and issue ant command. You will receive the following out put.

 
C:\anttest\example1>ant

Buildfile: build.xml

build:

[javac] Compiling 1 source file to C:\anttest\example1\build\src

BUILD SUCCESSFUL

Total time: 4 seconds

C:\anttest\example1>
   

Above mentioned process compiles the file and places in the build\src directory.

In the next lesson I will show you how to use ant to compile, build and deploy your web application to the Jboss 3.0

                         

Facing Programming Problem?
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

39 comments so far (post your own) View All Comments Latest 10 Comments:

An unexpected error has been detected by Java Runtime Environment:

EXCEPTION_ACCESS_VIOLATION

Posted by Milind on Sunday, 06.1.08 @ 13:42pm | #61690

log4j:ERROR Could not parse input source [org.xml.sax.InputSource@4b497311].
this is a error which generates when i m trying to run EJB .i m using log4j for writing debug statement .i m using IBM WAS 6.0 .
please help

Posted by roshanloyalka on Wednesday, 02.13.08 @ 14:47pm | #48139

Hi,
this is very good for beginers in java.
Thanks

Posted by indeevar on Monday, 12.24.07 @ 15:51pm | #43578

this is a good tutorial site and thanks alot!

Posted by Jimmy Lam on Sunday, 12.9.07 @ 12:26pm | #41640

Great Tutorial and very easy to understand..

Posted by Debugger on Monday, 11.19.07 @ 12:29pm | #37795

Hai Friends,
Roseindia site is very good site and easy understandable.i think it is fairly useful help to software people.
Thanks
Manu

Posted by manu on Monday, 11.12.07 @ 19:25pm | #36981

great one to read from the beginning.

Posted by Loganathan on Monday, 09.10.07 @ 14:38pm | #26576

Hi Friends,
The above example is very simple & easy to use. Thanks a lot for posting

Posted by Udhaya Ganesh on Wednesday, 09.5.07 @ 16:15pm | #25092

I have all workers on the ant now. It is like a tower of ants thanks to this tutorial. I ask, "what is ant?" and they now answer.

Posted by Java Boss on Thursday, 08.30.07 @ 03:33am | #24467

Hi
i am working in Accenture as a software developer my current project is on online intenet banking do u help in the project by making the use of the ejbs and how to make the proejects using the ejbs

Posted by jaggu on Thursday, 08.16.07 @ 11:28am | #23490

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Hot Web Programming Job

Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.