Search code examples
javaantexecless-unix

Ant exec command argument dealing with multiple files


I am using ant exec command to implement the less utility to view the source code of a bunch of .java files. (I know that there are other ways to do this like using concat)

So the call ant view works if I specify only one file:

<target name="view">
    <exec executable="less" dir=".">
        <arg value="Main.java"/>
    </exec>
</target>

But if I change my code to <arg value="*.java"/> to view all files, it actually searches for a file named *.java.

Apparently I can put a bunch of arg's for each file, but is there a way to do this with one arg ?


Solution

  • You can use foreach which requires ant-contrib

    <target name="view">
      <foreach target="call-less" param="file">
        <fileset dir="${src}" includes="**/*.java" />
      </foreach>
    </target>
    
    <target name="call-less">
        <exec executable="less">
            <arg value="${file}" />
        </exec>
    </target>