basics of ANT

G

gk

hi, i have downloaded and started reading the ant tutorial.

i am confused becuase some of the concepts , the tutorial (jakarta )
is not making clear.


my objective is to compile and run a java program.


my questions are as follows





it is called in order to compile and run you need a "build.xml" file .
where is that file ?

QUESTION 1: is it within ant distribution OR i have to make a
build.xml file myself?


The tutorial does not say anything about it. it just starts straight
forward with a demo "build.xml" file.

where do i put this "build.xml" file ?








QUESTION 2 :


i have a java code here.


package oata;

public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}



location of this code is "src/oata/HelloWorld.java"



Now tell, where do i put "build.xml" file ?
 
T

tin

You can put the build.xml file anywhere as long as your javac task is
pointed at the src directory. I would recommend putting it in src. Then
in the src directory, simply type ant.
 
V

Viator

gk said:
it is called in order to compile and run you need a "build.xml" file .
where is that file ?

QUESTION 1: is it within ant distribution OR i have to make a
build.xml file myself?

You will have to create the file your self.
The tutorial does not say anything about it. it just starts straight
forward with a demo "build.xml" file.

where do i put this "build.xml" file ?
You can put the file anywhere. The only thing is how the path in the
file are related to the files involved in build. The general practice
is to put the files in project base directory.
QUESTION 2 :


i have a java code here.


package oata;

public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
location of this code is "src/oata/HelloWorld.java"
Now tell, where do i put "build.xml" file ?

I will tell you BOSS.
The better place is to put the same in src.
Amit :)
 
G

gk

hi many thanks to you.
here is the build.xml file i am using

<?xml version="1.0"?>
<project name="HelloWorld" 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="oata.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>



i want to print each "property" in this XML file . it will help me to
understand whats happening in this XML file.


whats the print command ?
 
G

gk

when i typed "ant " there is 2 directory created build/classes.

but in a web application , there is no build directory, there is only
classes and src directory.

can i remove build directory and keep only classes directory ?


whats the change i have to do here..



<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"/>
 
V

Viator

Since you are using
<property name="src.dir" value="src"/>

The build.xml file should be in the parent directory of 'src' so that
src directory can be found.
Alternatively you can put the file anywhere and use the absolute path
to src as a value of src.dir property.

Amit :)
 
G

gk

Viator said:
Since you are using
<property name="src.dir" value="src"/>

The build.xml file should be in the parent directory of 'src' so that
src directory can be found.


yes, i have put my "build.xml" file in in the parent directory of
'src' . and it works.

i am not hapy. you know, it is creating a "build" directory and in that
"build" directory "classes" directory is created. i just dont need the
build directory, i need the "classes" directory only.

what changes i have to do in my build.xml file.




one more question ,

<property name="classes.dir"

do i have to hardcode the property always ??
 
R

Roedy Green

it is called in order to compile and run you need a "build.xml" file .
where is that file ?
You typically put it near the source files you want to compile.
QUESTION 1: is it within ant distribution OR i have to make a
build.xml file myself?
you must compose a build.xml file yourself that will compile the Java,
and build a jar.
The tutorial does not say anything about it. it just starts straight
forward with a demo "build.xml" file.

see my ant intro. http://mindprod.com/jgloss/ant.html
 
V

Viator

The build directory is getting created because of the entries

<property name="build.dir" value="build"/> AND
<property name="classes.dir" value="${build.dir}/classes"/>

instead just use

Can you explain the Q please

Amit :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top