Question

I am trying to copy the content of a folder with ant and need to keep the privileges of the files within.

I used the following ant code to do so:

<exec executable="cp">
    <arg line="-pr env/* ." />
</exec>

When I try the command manually it works, but when I run the ant file I get the following error:

deploy.add.op:
     [exec] cp: cannot access env/*
     [exec] Result: 2

BUILD SUCCESSFUL

Any suggestions?

Was it helpful?

Solution

Ant can't expand the * wildcard. You need to copy each sub folder on it's own:

<exec executable="cp">
    <arg line="-pr env/sub1 ." />
</exec>

<exec executable="cp">
    <arg line="-pr env/sub2 ." />
</exec>

.. 

or if this is unsufficient you may spawn a bash:

<exec executable="bash">
    <arg line="-c 'cp -pr env/* .'" />
</exec>

but the latter will work only on systems which having bash installed.

Also have a look at rsync instead of cp. Might be better because it can cleanup older files. However using tools like bash and rsync will make your script bound to *NIX systems.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top