diCoder
diCoder

Reputation: 191

pass an file into antfile when using ANT task

For example, I have two build.xml: build.xml and subbuild.xml. In the build.xml, it will use an ant task to call and run the subbuild.xml like this:

<target name="antCall1" >
    <ant antfile="${basedir}/cache/subBuildTarget/subbuild.xml" />
</target>

My question is like this: I have an "test.xml" next to the build.xml. How can I modified the codes above so that I can pass the "test.xml" into the subbuild.xml and do some operations in the subbuild.xml?

Actually, I want to pass the "test.xml" as a of a task in subbuild.xml. I am just confused about how to let the subbuild.xml get accessed to the "test.xml" in the build.xml. Thanks!

Upvotes: 0

Views: 310

Answers (1)

M A
M A

Reputation: 72844

Just set a property containing the name of the file in your build.xml before calling the subbuild.xml. An Ant subproject invoked using the ant task automatically inherits all properties set in their parent unless the attribute inheritAll is set to false. Alternatively you can pass the property to the subproject with a nested property element as suggested by CAustin in the comments.

First method:

<target name="antCall1" >
    <!-- since the file is in the same directory as the build.xml -->
    <property name="input.file" value="test.xml" />
    <ant antfile="${basedir}/cache/subBuildTarget/subbuild.xml" />
</target>

Second method:

<target name="antCall1" >
    <ant antfile="${basedir}/cache/subBuildTarget/subbuild.xml">
        <property name="input.file" value="test.xml" />
    </ant>
</target>

In subbuild.xml:

<loadfile property="file.contents" srcFile="${input.file}"/>
<echo message="${file.contents}" />

Upvotes: 3

Related Questions