AntImportTask

HomePage | RecentChanges | Preferences

Difference (from prior author revision) (major diff, minor diff)

Changed: 1,210c1
Working with the Ant 'import' task.

References



* http://ant.apache.org/manual/CoreTasks/import.html
* http://ant.apache.org/faq.html#xml-entity-include


A simple test in a single directory ==


Files ===

<!-- imported.xml -->
<project name="imported" basedir="." default="init">

<dirname property="imported.basedir" file="${ant.file.imported}"/>
<property file="${imported.basedir}/imported.properties"/>

<target name="init">
<echo message="name = ${name}"/>
</target>

</project>



<!-- importing.xml -->
<project name="importing" basedir="." default="init">

<import file="imported.xml"/>

<target name="init" >
<echo message="name = ${name}"/>
</target>

</project>



# imported.properties
name=Wendy

Output




Works as advertised


E:\java\ant-include\import>ant -f imported.xml
Buildfile: imported.xml

init:
[echo] name = Wendy

BUILD SUCCESSFUL
Total time: 0 seconds
E:\java\ant-include\import>ant -f importing.xml
Buildfile: importing.xml

init:
[echo] name = Wendy

BUILD SUCCESSFUL
Total time: 0 seconds
E:\java\ant-include\import>






Now including a file from the parent directory ==


Files ===

No change to imported.xml

<!-- imported.xml -->
<project name="imported" basedir="." default="init">

<dirname property="imported.basedir" file="${ant.file.imported}"/>
<property file="${imported.basedir}/imported.properties"/>

<target name="init">
<echo message="name = ${name}"/>
</target>

</project>


In importing.xml, changed path to imported.xml (added ../)

<!-- dirname/importing.xml -->
<project name="importing" basedir="." default="init">

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

<target name="init" >
<echo message="name = ${name}"/>
</target>

</project>


Slightly more complex properties


# imported.properties
first = Wendy
last = Smoak
name=${first} ${last}

Output




Still works as advertised...


Directory of E:\java\ant-include\subdir

07/24/2005 04:30 AM <DIR> .
07/24/2005 04:30 AM <DIR> ..
07/24/2005 04:34 AM <DIR> core
07/24/2005 04:23 AM 35 imported.properties
07/24/2005 04:19 AM 307 imported.xml
2 File(s) 342 bytes
3 Dir(s) 19,986,845,696 bytes free

E:\java\ant-include\subdir>ant -f imported.xml
Buildfile: imported.xml

init:
[echo] name = Wendy Smoak

BUILD SUCCESSFUL
Total time: 0 seconds
E:\java\ant-include\subdir>cd core

E:\java\ant-include\subdir\core>ant -f importing.xml
Buildfile: importing.xml

init:
[echo] name = Wendy Smoak

BUILD SUCCESSFUL
Total time: 0 seconds
E:\java\ant-include\subdir\core>





More complex properties ==


Files ===


<!-- imported.xml -->
<project name="imported" basedir="." default="init">

<!-- importing properties -->
<dirname property="shale.home" file="${ant.file.imported}"/>
<property file="${shale.home}/build.properties"/>

<!-- setting a property directly in the imported file -->
<property name="testprop" value="somevalue" />

<!-- avoiding making the user specify root.dir -->
<dirname property="root.dir" file="${ant.file}"/>

<target name="init">
<echo message="name = ${name}"/>
</target>

</project>



<!-- dirname/importing.xml -->
<project name="importing" basedir="." default="init">

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

<target name="init" >
<echo message="name = ${name}"/>
<echo message="root.dir = ${root.dir}"/>
<echo message="testprop = ${testprop}"/>
</target>

</project>



# imported.properties
first = Wendy
last = Smoak
name=${first} ${last}

Output




E:\java\ant-include\subdir\core>ant -f importing.xml
Buildfile: importing.xml

init:
[echo] name = Wendy Smoak
[echo] root.dir = E:\java\ant-include\subdir\core
[echo] testprop = somevalue

BUILD SUCCESSFUL
Total time: 0 seconds
E:\java\ant-include\subdir\core>




HomePage | RecentChanges | Preferences
This page is read-only | View other revisions
Last edited December 22, 2019 7:31 am by 78-93-98-198.dsl.wavetel.us (diff)
Search: