Robert H
Robert H

Reputation: 1663

can one include an XML file in an ant XML build file?

When I use Makefiles, I could include common.mk file, where I define in it some common definitions, such as classpath, and such.

I'd like to do the same with my build.xml files. I'd like to create a build.xml in each folder in my tree, this way I can build any part of the tree without having to edit the one top build.xml each time to tell it what to include.

This is how I did it with makefiles, and was very nice, since I can type 'make' from any folder in the tree, and using recursive make, it will build the tree part below where I was.

The problem with build.xml's, is that I find I duplicate same definitions in each build.xml (such as classpath, and compiler flags and what-have-you).

If I can include an xml file, then I can put all the common things in the common.xml file, in the root of the tree, and include that in each build.xml. (this is what I did with the Makefiles, I put everything in common.mk).

I do not like to use env. variables to define things, and prefer to use a file, a common file, that I use for the whole tree.

I am new at using ant, and so I might have overlooked this feature. If someone has an example of how to this also, this will be useful.

cheers,

Upvotes: 1

Views: 4080

Answers (1)

Dan O
Dan O

Reputation: 6090

Check out the documentation for including XML files and external Ant files: http://ant.apache.org/faq.html#xml-entity-include

to include a complete Ant build file inside of the current Ant file, you'll need to do something like this:

<?xml version="1.0"?>
<project name="test" default="test" basedir=".">

  <target name="setup">
    ...
  </target>

  <import file="./common.xml"/>

  ...

</project>

you'll need Ant 1.6 or newer.

Upvotes: 6

Related Questions