javaantfileset

Apache Ant - include parent directory in fileset


Is it possible to include a file from a parent directory, seen from the defined dir?

If I define a fileset with a given dir, lets say /home/user/workspace/src, is ti possible to include a file e.g /home/user/anotherworkspace/src/MyJavaClass.java?

Here the complete example, where the first include esist in the workspace:

<fileset id="myfileset" dir="/home/user/workspace/src">
    <include name="util/MyUtilClass.java"/>
    <include name="/home/user/anotherworkspace/src/MyJavaClass.java"/>
</fileset>

How to handle the second include?


Solution

  • Unfortunately you can't do that with one fileset, but you can create two sets and then merge them using union resource collection.

    <fileset id="myfileset1" dir="/home/user/workspace/src">
        <include name="util/MyUtilClass.java"/>
    </fileset>
    
    <fileset id="myfileset2" dir="/home/user/anotherworkspace/src">
        <include name="MyJavaClass.java"/>
    </fileset>
    
    <union id="myfileset">
        <resources refid="myfileset1" />
        <resources refid="myfileset2" />
    </union>
    

    After that you may use myfileset as usual.