Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use Ant to copy a folder?

Tags:

copy

ant

I'm trying to copy a directory using the Ant copy task.

I am a newbie at Ant; my current solution is:

<copy todir="${release_dir}/lib">
   <fileset dir="${libpath}" />
</copy>

I'm wondering if there is a better and shorter way to accomplish the same thing?

like image 761
defoo Avatar asked Mar 19 '10 04:03

defoo


People also ask

What is FileSet in Ant?

A FileSet is a group of files. These files can be found in a directory tree starting in a base directory and are matched by patterns taken from a number of PatternSets and Selectors. PatternSets can be specified as nested <patternset> elements.

What is PathElement in ant?

Path: This object represents a path as used by CLASSPATH or PATH environment variable. A path might also be described as a collection of unique filesystem resources. and PathElement: Helper class, holds the nested <pathelement> values.

What is target in Ant build?

A target is a container of tasks and datatypes that cooperate to reach a desired state during the build process. Targets can depend on other targets and Apache Ant ensures that these other targets have been executed before the current target.


2 Answers

First of all, those are the examples from Ant documentation:

Copy a directory to another directory

<copy todir="../new/dir">
  <fileset dir="src_dir"/>   
</copy>

Copy a set of files to a directory

<copy todir="../dest/dir">
  <fileset dir="src_dir">
    <exclude name="**/*.java"/>
  </fileset>
</copy>

<copy todir="../dest/dir">
  <fileset dir="src_dir" excludes="**/*.java"/>   
</copy>

Copy a set of files to a directory, appending .bak to the file name on the fly

<copy todir="../backup/dir">
  <fileset dir="src_dir"/>
  <globmapper from="*" to="*.bak"/>   
</copy>

Secondly, here is the whole documentation about copy task.

like image 186
zeroDivisible Avatar answered Nov 10 '22 21:11

zeroDivisible


Just because the docs were not very clear to me, and because the time I spent can serve others:

The docs say that this "copies a directory (dir1) to another directory (dest)":

<copy todir="../new/dest">
  <fileset dir="src/dir1"/>   
</copy>

Actually, this does not mean "copy dir1 inside dest", but rather "copy the contents of dir1 inside dest".

(In general, in Ant, the "root dir" of a filesets -as well at the todir attribute- is not considered as being part of the set itself.)

To place the directory dir1 inside dest one has several alternatives (none totally satisfying to me - and I'd imagined that the new DirSet would help here, but no)

<copy todir="../new/dest/dir1">
  <fileset dir="src/dir1"/>   
</copy>

or

<copy todir="../new/dest">
  <fileset dir="src" includes="dir1/**"/>
</copy>

See also here and here.

like image 24
leonbloy Avatar answered Nov 10 '22 20:11

leonbloy