Imports another build file into the current project.
On execution it will read another Ant file into
the same Project. This means that it basically works like the
Entity
Includes as explained in the Ant FAQ, as if the imported file was
contained in the importing file, minus the top <project>
tag.
The import task may only be used as a top-level task. This means that it may not be used in a target.
There are two further functional aspects that pertain to this task and that are not possible with entity includes:
Suppose your main build file called importing.xml
imports a build file imported.xml, located anywhere on
the file system, and imported.xml reads a set of
properties from imported.properties:
<-- importing.xml -->
<project name="importing" basedir="." default="...">
<import file="${path_to_imported}/imported.xml"/>
</project>
<-- imported.xml -->
<project name="imported" basedir="." default="...">
<property file="imported.properties"/>
</project>
This snippet however will resolve imported.properties
against the basedir of importing.xml, because the basedir
of imported.xml is ignored by Ant. The right way to use
imported.properties is:
<-- imported.xml -->
<project name="imported" basedir="." default="...">
<dirname property="imported.basedir" file="${ant.file.imported}"/>
<property file="${imported.basedir}/imported.properties"/>
</project>
As explained above ${ant.file.imported} stores the
path of the build script, that defines the project called
imported, (in short it stores the path to
imported.xml) and <dirname> takes its
directory. This technique also allows imported.xml to be
used as a standalone file (without being imported in other
project).
| Attribute | Description | Required |
| file | The file to import. If this is a relative file name, the file name will be resolved relative to the importing file. Note, this is unlike most other ant file attributes, where relative files are resolved relative to ${basedir}. | Yes |
| optional | If true, do not stop the build if the file does not exist, default is false. | No |
<import file="../common-targets.xml" />
<import file="${deploy-platform}.xml" />
Copyright © 2003-2004 The Apache Software Foundation. All rights Reserved.