ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tim Gordon" <>
Subject Import - bug or feature?
Date Fri, 27 Jun 2003 12:53:37 GMT
I know that the comments around ImportTask recommend that absolute file
paths be used, but I thought that relative file paths in imported files
would be defined relative to the base dir of the project that does the
import, which is what seems to happen in the simple case where one ANT file
imports another as a library. However, if an import is shared between two
different ANT files which call each other, looking at how <import> is

Lets say I've got two ant files,

/basedir/callerdir/caller.xml and

both of which contain

<import file="../libdir/lib.xml"/>

Inside lib.xml we've got a stock-implementation of a target which involves

<project name="lib">
  <target name="projectClassPath">
    <path id="project.class.path">
      <pathelement location="../build"/>
      <fileset dir="../lib">
        <include name="**/*.jar"/>
        <include name="**/*.zip"/>
    <property name="project.class.path" refid="project.class.path"/>

Now ANT first encounters the <import file="lib.xml"/> in caller.xml. If we

ant -f /basedir/callerdir/caller.xml projectClassPath

Then our paths are defined relative to the basedir of caller.xml, which is
what you'd expect.

However, if caller.xml has the following snippet:

  <target name="call">
    <ant antfile="../../calleedir/callee.xml" target="projectClassPath"/>

Then when caller.xml invokes a target in callee.xml

ant -f /basedir/callerdir/caller.xml call

we get "Duplicated project name in import. Project lib defined first in
/basedir/callerdir/caller.xml and again in /basedir/calleedir/callee.xml".

There is more to it than just the warning - when the echo occurs the paths
are defined relative to caller.xml, not callee.xml, as we'd expect.

If I <ant> one ant file from another, I would have thought it's symantically
like invoking another JVM. What's actaully happenend here is that it looks
like callee.xml is invoking targets which have really been defined in

If it's a bug I'll look into a potential fix. Unless it's supposed to work
that way for some reason...

Tim Gordon

Allustra Limited
1 Royal Exchange Avenue
Tel 020 7464 4190
Tel 020 7464 4194

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message