ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Weintraub <>
Subject Re: if files have been copied physically, then execute some target
Date Mon, 11 May 2009 15:06:40 GMT
Are you willing to use the Ant Contrib's <outofdate> task?

This will compare a set of targets vs. a set of sources and run the
task only if the sources and targets match. You can also set a
property to set if the targets are out of date when compared to the

For example:

<target name="run"

<target name="copy_files">
    <outofdate property="files.copied">
        <srcfiles dir="${basedir}/src_dir"/>
        <targetfiles dir="${basedir}/new/dir"/>
            <copy todir="${basedir}/new/dir">
                <fileset dir="${basedir}/src_dir"/>

The above will compare all files in "${basedir}/src_dir" and
"${basedir}/new/dir", and set the attribute "files.copied" to "true".
Not only that, but it will then run the <sequential> subtask which
will actually do the copying.

Now, the target "run" will only execute if the "files.copied"
attribute has been set, and the files have actually been copied.

There is a standard <uptodate> task, and it is suppose to be able to
take a <mapper> to do the file comparisons, but I have been unable to
get it to use the <mapper type="identity"> type which is what I need
to do this type of comparison.

It is possible to use the <uptodate> task if you compare just one
target file with its source file, and make the assumption that if this
one target is up to date, all targets are up to date. However, that
may be an invalid assumption.

On Fri, May 8, 2009 at 4:03 PM, walki2 <> wrote:
> Hi,
> My ant code looks something like this:
> ...
> <target name="copy_files">
>    <copy todir="../new/dir">
>        <fileset dir="src_dir"/>
>    </copy>
> </target>
> <target name="run" depends="copy_files">
>     <java jar="some_jar.jar" fork="true"/>
> </target>
> ...
> I would like the run target to be exectuted only if files have been copied.
> If I do not do a clean and files have not been modified, no files are
> actually copied but the run target is still executed.
> How can I do this?
> Thanks,
> walki
> --
> View this message in context:
> Sent from the Ant - Users mailing list archive at
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

David Weintraub

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message