boaz shor
boaz shor

Reputation: 299

How does the import files mechanisem work in Apache ANT

I'm working on building a large scale project, as part of the build I defined a path in some xml and overridden it in another xml that imports it (or imports a file that imports it). I noticed that the order of the imports and the location of the overridden path tag in the importing files changes the behavior of the build. But, I couldn't find the logic behind it. How does the import work exactly? Thanks

Upvotes: 2

Views: 1347

Answers (1)

bable5
bable5

Reputation: 111

The value of ant property cannot be changed once set. If you import a file and the file sets some properties, any other declaration of a property after the import with the same name as a property in the imported file will be ignored.

Suppose you have an external file, file1.xml, which declares a property, foo.

file1.xml: <property name="foo" value="bar"/>

Then, in the main file, where you declare the property foo matters in relation to where you import file1.xml.

Suppose you do:

<import file="file1.xml"/>

<property name="foo" value="baz"/>

Then property foo will have a value of bar. On the other hand, if you do:

<property name="foo" value="baz"/>

<import file="file1.xml"/>

Then property foo will have the value baz.

The moral of the story is to define any properties whose value you wish to override before you import a file that also declares those properties.

See http://ant.apache.org/manual/Tasks/property.html for the ant property task documentation.

Upvotes: 1

Related Questions