basics of ANT  
Author Message
gk





PostPosted: 2005-12-13 16:51:00 Top

java-programmer, basics of ANT 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.

>md src


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 ?

 
tin





PostPosted: 2005-12-13 17:24:00 Top

java-programmer >> basics of ANT 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.

 
Viator





PostPosted: 2005-12-13 17:25:00 Top

java-programmer >> basics of ANT
gk wrote:
> 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.
>
> >md src
>
>
> 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 :-)

 
 
gk





PostPosted: 2005-12-13 17:36:00 Top

java-programmer >> basics of ANT 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 ?

 
 
Viator





PostPosted: 2005-12-13 17:43:00 Top

java-programmer >> basics of ANT 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 :-)

 
 
gk





PostPosted: 2005-12-13 17:43:00 Top

java-programmer >> basics of ANT 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"/>

 
 
Timbo





PostPosted: 2005-12-13 17:50:00 Top

java-programmer >> basics of ANT gk wrote:
> whats the print command ?
>
If you are running this from a terminal, then:
<echo message="your message">

will print to the terminal.

Tim
 
 
gk





PostPosted: 2005-12-13 17:51:00 Top

java-programmer >> basics of ANT Viator wrote:

> 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 ??

 
 
Roedy Green





PostPosted: 2005-12-13 20:13:00 Top

java-programmer >> basics of ANT On 13 Dec 2005 00:50:40 -0800, "gk" <email***@***.com> wrote, quoted
or indirectly quoted someone who said :

>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

--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
 
Roedy Green





PostPosted: 2005-12-13 20:14:00 Top

java-programmer >> basics of ANT On 13 Dec 2005 01:35:34 -0800, "gk" <email***@***.com> wrote, quoted
or indirectly quoted someone who said :

> <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>

use genjar for this step. It will collect just the files you need
automatically.

See http://mindprod.com/jgloss/ant.html
http://mindprod.com/jgloss/genjar.html
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
 
Roedy Green





PostPosted: 2005-12-13 20:16:00 Top

java-programmer >> basics of ANT On 13 Dec 2005 01:35:34 -0800, "gk" <email***@***.com> wrote, quoted
or indirectly quoted someone who said :

>
>whats the print command ?
e.g. <echo message="compiling ${package.dir} tree." />
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
 
Viator





PostPosted: 2005-12-13 23:01:00 Top

java-programmer >> basics of ANT 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
<property name="classes.dir" value="classes"/>

>> <property name="classes.dir"
>>do i have to hardcode the property always ??

Can you explain the Q please

Amit :-)