Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2005

Tip: Looking for answers? Try searching our database.

basics of ANT

Thread view: 
gk - 13 Dec 2005 08:50 GMT
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 - 13 Dec 2005 09:23 GMT
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.
gk - 13 Dec 2005 09:35 GMT
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  ?
gk - 13 Dec 2005 09:42 GMT
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"/>
Viator - 13 Dec 2005 09:43 GMT
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 - 13 Dec 2005 09:51 GMT
> 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 ??
Viator - 13 Dec 2005 15:01 GMT
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 :-)
Timbo - 13 Dec 2005 09:49 GMT
> whats the print command  ?

If you are running this from a terminal, then:
<echo message="your message">

will print to the terminal.

Tim
Roedy Green - 13 Dec 2005 12:14 GMT
> <target name="jar" depends="compile">
>        <mkdir dir="${jar.dir}"/>
[quoted text clipped - 4 lines]
>            </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
Signature

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

Roedy Green - 13 Dec 2005 12:15 GMT
>whats the print command  ?
e.g. <echo message="compiling ${package.dir} tree." />
Signature

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

Viator - 13 Dec 2005 09:24 GMT
> 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 :
>
[quoted text clipped - 9 lines]
>     }
> }

> 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 :-)
Roedy Green - 13 Dec 2005 12:13 GMT
>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

Signature

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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.