ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michel CASABIANCA <>
Subject Re: include construct?
Date Tue, 04 Apr 2000 23:30:16 GMT

"Craig R. McClanahan" <> writes:
> Scott M Stark wrote:
> > Is there a mechanism like the gnumake include or -include in Ant?
> > I tried using an xml:link hoping the parser would just magically
> > include it but Ant sees the include element and wants to treat it
> > as a task.
> There is not an "include" mechanism like what you're describing in
> Ant right now.  However, it would not be hard using some of the
> shell tools that manipulate text files to construct a buildfile on
> the fly by copying in standard components, before feeding the
> resulting file to Ant.  You could do this with the C preprocessor
> (cpp), or the m4 utility, for example.

Using shell tools is not a good solution as the purpose of Ant
is independancy against platform.

But build.xml files are XML files (obviously), so you can use
entities to include another XML file, like that :

file build.xml
<?xml version="1.0" encoding="iso-8859-1"?>

<!DOCTYPE project PUBLIC "-//ANT//DTD project//EN" "project.dtd" [
<!ENTITY include SYSTEM "message.xml">

<project name="test" default="task" basedir=".">

 <target name="task">
  <echo message="Hello"/>


This file includes the following :

file message.xml
<echo message="World !"/>

Thus when running ant, you get :

  [casa test]$ ant
  Buildfile: build.xml
  Project base dir set to: /home/casa/tmp/test
  Executing Target: task
  World !
  Completed in 2 seconds

But you must have a DTD for project files :o)

| Michel CASABIANCA         |   | 
|        | Articles sur Java et XML       | 
| Développement Java et XML | Applications et Applets de Jeu |

View raw message