ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dino Valente <d...@3dstockcharts.com>
Subject Re: Including other antfiles
Date Wed, 09 Aug 2000 17:12:26 GMT
At 01:24 PM 8/9/00, you wrote:
>In my original MAKE project I have the following pattern:
>
>   INCBUILDMAKEFILES = X Y Z
>   include $(INCBUILDMAKEFILES)
>
>   TargetA: TargetX.A TargetZ.B
>   
>Where the dependencies of TargetA do not exist in the same make file, but
>in one of the included files.
>
>One way I might translate this to Ant is:
>
>   <target name="TargetA">
>      <ant antfile="X"
>           dir=" ... "
>           target="TargetX.B" />
>          
>      <ant antfile="Z"
>           dir=" ... "
>           target="TargetZ.B" />
>
>      ...
>
>   </target>
>   
>My questions:
>
>Is this the best way?
>Is this the only way?
>Am I missing something obvious?
>Is there some way to call an "include" to include the targets of another
>ant file?
>

This is the response I got for the last question (which I think is the most
important).

==========================================
You can do this using XML entities.  Here's a simple example:

===========
 build.xml
===========
<?xml version="1.0"?>

<!DOCTYPE project [
     <!ENTITY usage SYSTEM "usage.ent">
     <!ENTITY zip SYSTEM "zip.ent">
     <!ENTITY compile SYSTEM "compile.ent">
     <!ENTITY dist SYSTEM "dist.ent">
     <!ENTITY test SYSTEM "test.ent">
]>

<project name="mypackage" default="main" basedir=".">

     <!-- Usage -->
     &usage;

     <!-- Zip Targets -->
     &zip;

     <!-- Compile Targets -->
     &compile;

     <!-- Distribution Targets -->
     &dist;

     <!-- Test Targets -->
     &test;

</project>

Then, you build each of your ".ent" (.ent is just a convention...it can be
anything) files:

=============
 compile.ent
=============
<target name="compile">
     <javac .../>
</target>

=================================================

Depending on the parser the line      
	<!ENTITY usage SYSTEM "usage.ent">
should be replaced with 
	<!ENTITY usage SYSTEM "file:usage.ent">


This solution is ok when the file is relative to the build file and you
execute the ant application in that directory. However, if you have a build
file in the parent directory (which basically goes through  subdirectories
to call build) then it doesn't work since the current working directory is
taken from the parent directory for the <!ENTITY usage SYSTEM "usage.ent">
line. The only way to get around this is to use absolute paths (which is
unacceptable for development at my company). 

This ability to include other ant files is really crucial in order for me
to use ant. Othersize, I will be typing in the same stuff for all my
projects (I have 20 projects). People have suggested to use the following
method:

<project name="fooproject" basedir=".">
      <ant antfile="X" dir=" ... " target="TargetX.B"> 
		<property name="name" value="foo" />
	</ant>
</project>

where X is the general file. This doesn't work for me since you would have
to define all the rules again the build file and propagate the action to
the general build file (e.g I have separate rules for building the jar
file, cleaning the .class files and generating javadocs). Maintanence is a
nightmare.

Ant is a very good product. I was hooked. However, I was very disappointed
on its ability to not handle complex projects. Basically, I wanted the
ability build each project separately and the ability to build all my
projects in an efficient way. With make, it is a no brainer except for
compiling java files. This is why I like ant so much is that it takes care
of this aspect for me. I was also disappointed on how Ant handles property
values (you can only set it once and can never override them). I'm still
hoping someone will post an example that will convince me that Ant is the
answer to my problem (so far no one has). 

dino



Mime
View raw message