Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Ant, Maven and Other Build Tools and the fly likes Ant usage Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Ant usage" Watch "Ant usage" New topic

Ant usage

Kiran Baratam

Joined: Sep 03, 2003
Posts: 27
Hi all
I am new to Ant and i heard that ant can be used as a build tool but never worked on it and would like to write know certain things.
i am working on a project which uses some jar files which are required to run the application.
i would like to make a directory as
c:/production/execute/ and copy all the jar required to run and these jar are avilable in c:/lib/.
my java files are in c:/com/info/stock
i want to compile the jave files in this directory and copy to above directory i.e c:/production/execute/com/info/stock
First i would like to know whether ant is ment for doing things like this
and if so can some body help me in doing this.
i installed ant in my machine.
Please help me.
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
Kiran -
This is exactly what Ant is for .
Since you're new to Ant, I'd recommend you to start with basic things, like compiling and creating your own targets.
The Ant tutorial is what you need to get into speed. Once you understand, look at all the options that Ant has to copy files, delete/clean directories, etc. If you have any specific question let us know..

I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
Kiran Baratam

Joined: Sep 03, 2003
Posts: 27
Hi Andres
Thanks for the reply.
I am going through the turorial and trying out some small examples.
I could able to compile and create directory as i need.
Actuall i had taken a sample file and started working on it.
i have a small doubt.
in the file i had take there is a line like below
<target name="clean" description="Delete build files">
<delete dir="${build}" />
what does it do???
i did not find any activity by these lins.I tried by removinf also.
Can you please let me know.
Juanjo Bazan
Ranch Hand

Joined: Feb 04, 2002
Posts: 231
That delete task is suposed to be used to remove any temp. directory used in previous tasks(the diretory defined in "build").
Notice that if the target "clean" is not invoked it will not execute, maybe thats why you don't see any activity related with it.
Kiran Baratam

Joined: Sep 03, 2003
Posts: 27
Here is my build.xml.
i am able to compile and copy the classes in specified directory.I did not understand why delete option is not i missing some thing??
Please help me.
<project name="AntExample" default="compile" basedir=".">
<!-- Set the source directory from where the java files need to be taken -->
<property name="src" location="./com/chase/impb/tokyo/matrix2/automate" />
<!-- Set the destination directory where the class files need to be copied -->
<property name="build" location="d:/DINO_Test/cfunds" />
<!-- Set all the dependency jar/class files directory -->
<property name="lib" location="lib" />

<!-- Load local and user build preferences -->
<!-- Specify dependent jars and their locations which are not avilable in lib directory -->
<property file="${user.home}/" />
<property file="" />
<!-- Set compile classpath -->
<path id="compile.classpath">
<fileset dir="${lib}">
<include name="**/*.jar" />
<!-- list the jars which are not avilable in lib directory insted in a different place specified in properties file -->
<pathelement location="${iText.jar}" />
<!-- targets -->
<target name="compile" description="Compile the source and copy resource files.">
<mkdir dir="${build}" />
<!-- Specify the command you want to execute on the source directory with class path if needed -->
<javac srcdir="${src}/java" destdir="${build}">
<classpath refid="compile.classpath" />
<copy todir="d:/DINO_Test/cfunds" includeEmptyDirs="no">
<fileset dir="${src}/resources" />
<target name="clean" description="Delete build files">
<delete dir="${build}" />
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561

Disclaimer: I have NOT tested it.
[ October 05, 2003: Message edited by: Andres Gonzalez ]
I agree. Here's the link:
subject: Ant usage
Similar Threads
How do i find out the relative path for my jar?
Need Servlets 4a Help
Ant with JUnit and Emma: Req Urgent Help
Ant building error
AndroMDA using Ant