2001-02-13 12:32:01 +00:00
|
|
|
<html>
|
|
|
|
|
|
|
|
<head>
|
|
|
|
<meta http-equiv="Content-Language" content="en-us">
|
2005-04-29 18:58:16 +00:00
|
|
|
<link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
|
2001-12-04 03:06:04 +00:00
|
|
|
<title>Copy Task</title>
|
2001-02-13 12:32:01 +00:00
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<h2><a name="copy">Copy</a></h2>
|
|
|
|
<h3>Description</h3>
|
2005-09-28 18:42:46 +00:00
|
|
|
<p>Copies a file or resource collection to a new file or directory. By default, files are
|
2001-02-13 12:32:01 +00:00
|
|
|
only copied if the source file is newer than the destination file,
|
2002-06-01 12:26:43 +00:00
|
|
|
or when the destination file does not exist. However, you can explicitly
|
2002-04-01 03:49:51 +00:00
|
|
|
overwrite files with the <code>overwrite</code> attribute.</p>
|
2003-02-05 13:14:33 +00:00
|
|
|
|
2005-09-28 18:42:46 +00:00
|
|
|
<p><a href="../CoreTypes/resources.html#collection">Resource
|
|
|
|
Collection</a>s are used to select a group of files to copy. Only
|
|
|
|
file system based resource collections are supported, this includes <a
|
|
|
|
href="../CoreTypes/fileset.html">fileset</a>s, <a
|
|
|
|
href="../CoreTypes/filelist.html">filelist</a> and <a
|
|
|
|
href="../using.html#path">path</a>. To use a resource collection, the
|
|
|
|
<code>todir</code> attribute must be set.</p>
|
2003-02-05 13:14:33 +00:00
|
|
|
|
|
|
|
<p>
|
|
|
|
<strong>Note: </strong>If you employ filters in your copy operation, you should
|
|
|
|
limit the copy to text files. Binary files will be corrupted by the copy operation.
|
|
|
|
This applies whether the filters are implicitly defined by the
|
|
|
|
<a href="filter.html">filter</a> task or explicitly provided to the copy
|
|
|
|
operation as <a href="../CoreTypes/filterset.html">filtersets</a>
|
|
|
|
</p>
|
|
|
|
|
2001-02-13 12:32:01 +00:00
|
|
|
<h3>Parameters</h3>
|
|
|
|
<table border="1" cellpadding="2" cellspacing="0">
|
|
|
|
<tr>
|
|
|
|
<td valign="top"><b>Attribute</b></td>
|
|
|
|
<td valign="top"><b>Description</b></td>
|
|
|
|
<td align="center" valign="top"><b>Required</b></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">file</td>
|
|
|
|
<td valign="top">The file to copy.</td>
|
2002-06-01 12:26:43 +00:00
|
|
|
<td valign="top" align="center">Yes, unless a nested
|
2005-09-28 18:42:46 +00:00
|
|
|
resource collection element is used.</td>
|
2001-02-13 12:32:01 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">preservelastmodified</td>
|
|
|
|
<td valign="top">Give the copied files the same last modified
|
2005-03-03 16:43:32 +00:00
|
|
|
time as the original source files.</td>
|
2002-04-01 03:49:51 +00:00
|
|
|
<td valign="top" align="center">No; defaults to false.</td>
|
2001-02-13 12:32:01 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">tofile</td>
|
|
|
|
<td valign="top">The file to copy to.</td>
|
2002-04-01 03:49:51 +00:00
|
|
|
<td valign="top" align="center" rowspan="2">With the <code>file</code>
|
|
|
|
attribute, either <code>tofile</code> or <code>todir</code> can be used.
|
2005-09-28 18:42:46 +00:00
|
|
|
With nested resource collection elements, if the number of included files
|
2002-04-01 03:49:51 +00:00
|
|
|
is greater than 1, or if only the <code>dir</code> attribute is
|
|
|
|
specified in the <code><fileset></code>, or if the
|
|
|
|
<code>file</code> attribute is also specified, then only
|
|
|
|
<code>todir</code> is allowed.</td>
|
2001-02-13 12:32:01 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">todir</td>
|
|
|
|
<td valign="top">The directory to copy to.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">overwrite</td>
|
|
|
|
<td valign="top">Overwrite existing files even if the destination
|
2002-04-01 03:49:51 +00:00
|
|
|
files are newer.</td>
|
|
|
|
<td valign="top" align="center">No; defaults to false.</td>
|
2001-02-13 12:32:01 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">filtering</td>
|
2002-04-01 03:49:51 +00:00
|
|
|
<td valign="top">Indicates whether token filtering using the global
|
|
|
|
build-file filters should take place during the copy.
|
|
|
|
<em>Note</em>: Nested <code><filterset></code> elements will
|
|
|
|
always be used, even if this attribute is not specified, or its value is
|
|
|
|
<code>false</code> (<code>no</code>, or <code>off</code>).</td>
|
|
|
|
<td valign="top" align="center">No; defaults to false.</td>
|
2001-02-13 12:32:01 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">flatten</td>
|
2002-04-01 03:49:51 +00:00
|
|
|
<td valign="top">Ignore the directory structure of the source files,
|
|
|
|
and copy all files into the directory specified by the <code>todir</code>
|
|
|
|
attribute. Note that you can achieve the same effect by using a
|
|
|
|
<a href="../CoreTypes/mapper.html#flatten-mapper">flatten mapper</a>.</td>
|
|
|
|
<td valign="top" align="center">No; defaults to false.</td>
|
2001-02-13 12:32:01 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">includeEmptyDirs</td>
|
2002-04-01 03:49:51 +00:00
|
|
|
<td valign="top">Copy any empty directories included in the FileSet(s).
|
|
|
|
</td>
|
|
|
|
<td valign="top" align="center">No; defaults to true.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">failonerror</td>
|
2004-12-07 23:42:41 +00:00
|
|
|
<td valign="top">If false, log a warning message, but do not stop the
|
2003-05-14 11:53:41 +00:00
|
|
|
build, when the file to copy does not exist or one of the nested
|
2003-05-19 15:37:31 +00:00
|
|
|
filesets points to a directory that doesn't exist or an error occurs
|
|
|
|
while copying.
|
2002-04-01 03:49:51 +00:00
|
|
|
</td>
|
|
|
|
<td valign="top" align="center">No; defaults to true.</td>
|
2001-02-13 12:32:01 +00:00
|
|
|
</tr>
|
2002-06-01 12:26:43 +00:00
|
|
|
<tr>
|
|
|
|
<td valign="top">verbose</td>
|
|
|
|
<td valign="top">Log the files that are being copied.</td>
|
|
|
|
<td valign="top" align="center">No; defaults to false.</td>
|
|
|
|
</tr>
|
2003-03-27 16:32:19 +00:00
|
|
|
<tr>
|
|
|
|
<td valign="top">encoding</td>
|
|
|
|
<td valign="top">The encoding to assume when filter-copying the
|
|
|
|
files. <em>since Ant 1.5</em>.</td>
|
|
|
|
<td align="center">No - defaults to default JVM encoding</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">outputencoding</td>
|
|
|
|
<td valign="top">The encoding to use when writing the files.
|
|
|
|
<em>since Ant 1.6</em>.</td>
|
|
|
|
<td align="center">No - defaults to the value of the encoding
|
|
|
|
attribute if given or the default JVM encoding otherwise.</td>
|
|
|
|
</tr>
|
2003-07-24 13:14:21 +00:00
|
|
|
<tr>
|
2004-01-29 14:12:04 +00:00
|
|
|
<td valign="top">enablemultiplemappings</td>
|
2003-07-24 13:14:21 +00:00
|
|
|
<td valign="top">
|
|
|
|
If true the task will process to all the mappings for a
|
|
|
|
given source path. If false the task will only process
|
|
|
|
the first file or directory. This attribute is only relevant
|
|
|
|
if there is a mapper subelement.
|
|
|
|
<em>since Ant 1.6</em>.</td>
|
|
|
|
<td align="center">No - defaults to false.</td>
|
|
|
|
</tr>
|
2003-09-23 13:16:04 +00:00
|
|
|
<tr>
|
|
|
|
<td valign="top">granularity</td>
|
|
|
|
<td valign="top">The number of milliseconds leeway to give before
|
|
|
|
deciding a file is out of date. This is needed because not every
|
|
|
|
file system supports tracking the last modified time to the
|
2005-01-04 19:39:01 +00:00
|
|
|
millisecond level. Default is 1 second, or 2 seconds on DOS
|
2003-09-23 13:16:04 +00:00
|
|
|
systems. This can also be useful if source and target files live
|
|
|
|
on separate machines with clocks being out of sync. <em>since Ant
|
2004-05-25 12:12:39 +00:00
|
|
|
1.6.2</em>.</td>
|
2003-09-23 13:16:04 +00:00
|
|
|
</tr>
|
2001-02-13 12:32:01 +00:00
|
|
|
</table>
|
|
|
|
<h3>Parameters specified as nested elements</h3>
|
2002-06-01 12:26:43 +00:00
|
|
|
|
2005-09-28 18:42:46 +00:00
|
|
|
<h4>fileset or any other filesystem based resource collection</h4>
|
|
|
|
<p><a href="../CoreTypes/resources.html#collection">Resource
|
|
|
|
Collection</a>s are used to select groups of files to copy. To use a
|
|
|
|
resource collection, the <code>todir</code> attribute must be set.</p>
|
|
|
|
<p>Prior to Ant 1.7 only <code><fileset></code> has been
|
|
|
|
supported as a nested element.</p>
|
2002-06-01 12:26:43 +00:00
|
|
|
|
2001-02-13 12:32:01 +00:00
|
|
|
<h4>mapper</h4>
|
2002-04-01 03:49:51 +00:00
|
|
|
<p>You can define filename transformations by using a nested <a
|
2001-08-30 13:23:14 +00:00
|
|
|
href="../CoreTypes/mapper.html">mapper</a> element. The default mapper used by
|
|
|
|
<code><copy></code> is the <a
|
2002-04-01 03:49:51 +00:00
|
|
|
href="../CoreTypes/mapper.html#identity-mapper">identity mapper</a>.</p>
|
2004-12-10 13:17:51 +00:00
|
|
|
<p>
|
|
|
|
<em>Since Ant 1.6.3</em>,
|
|
|
|
one can use a filenamemapper type in place of the mapper element.
|
|
|
|
</p>
|
2002-06-01 12:26:43 +00:00
|
|
|
|
2005-09-28 18:42:46 +00:00
|
|
|
<p>Note that the source name handed to the mapper depends on the
|
|
|
|
resource collection you use. If you use <code><fileset></code>
|
|
|
|
or any other collection that provides a base directory, the name
|
|
|
|
passed to the mapper will be a relative filename, relative to the base
|
|
|
|
directory. In any other case the absolute filename of the source will
|
|
|
|
be used.</p>
|
|
|
|
|
2001-08-30 13:23:14 +00:00
|
|
|
<h4>filterset</h4>
|
2002-04-01 03:49:51 +00:00
|
|
|
<p><a href="../CoreTypes/filterset.html">FilterSet</a>s are used to replace
|
2002-06-01 12:26:43 +00:00
|
|
|
tokens in files that are copied.
|
2002-04-01 03:49:51 +00:00
|
|
|
To use a FilterSet, use the nested <code><filterset></code> element.</p>
|
2002-06-01 12:26:43 +00:00
|
|
|
|
|
|
|
<h4>filterchain</h4>
|
|
|
|
<p>The Copy task supports nested <a href="../CoreTypes/filterchain.html">
|
|
|
|
FilterChain</a>s.</p>
|
|
|
|
|
2002-07-22 11:12:16 +00:00
|
|
|
<p>
|
2004-11-19 09:07:12 +00:00
|
|
|
If <code><filterset></code> and <code><filterchain></code> elements are used inside the
|
|
|
|
same <code><copy></code> task, all <code><filterchain></code> elements are processed first
|
|
|
|
followed by <code><filterset></code> elements.
|
2002-07-22 11:12:16 +00:00
|
|
|
</p>
|
|
|
|
|
2001-02-13 12:32:01 +00:00
|
|
|
<h3>Examples</h3>
|
|
|
|
<p><b>Copy a single file</b></p>
|
|
|
|
<pre>
|
|
|
|
<copy file="myfile.txt" tofile="mycopy.txt"/>
|
|
|
|
</pre>
|
2002-04-01 03:49:51 +00:00
|
|
|
<p><b>Copy a single file to a directory</b></p>
|
2001-02-13 12:32:01 +00:00
|
|
|
<pre>
|
2002-04-01 03:49:51 +00:00
|
|
|
<copy file="myfile.txt" todir="../some/other/dir"/>
|
2001-02-13 12:32:01 +00:00
|
|
|
</pre>
|
|
|
|
<p><b>Copy a directory to another directory</b></p>
|
|
|
|
<pre>
|
|
|
|
<copy todir="../new/dir">
|
|
|
|
<fileset dir="src_dir"/>
|
|
|
|
</copy>
|
|
|
|
</pre>
|
|
|
|
<p><b>Copy a set of files to a directory</b></p>
|
|
|
|
<pre>
|
2002-09-04 11:05:19 +00:00
|
|
|
<copy todir="../dest/dir">
|
|
|
|
<fileset dir="src_dir">
|
2001-02-13 12:32:01 +00:00
|
|
|
<exclude name="**/*.java"/>
|
|
|
|
</fileset>
|
|
|
|
</copy>
|
|
|
|
|
2002-09-04 11:05:19 +00:00
|
|
|
<copy todir="../dest/dir">
|
2001-12-04 03:06:04 +00:00
|
|
|
<fileset dir="src_dir" excludes="**/*.java"/>
|
2001-02-13 12:32:01 +00:00
|
|
|
</copy>
|
|
|
|
</pre>
|
2002-04-01 03:49:51 +00:00
|
|
|
<p><b>Copy a set of files to a directory, appending
|
|
|
|
<code>.bak</code> to the file name on the fly</b></p>
|
2001-02-13 12:32:01 +00:00
|
|
|
<pre>
|
2002-09-04 11:05:19 +00:00
|
|
|
<copy todir="../backup/dir">
|
|
|
|
<fileset dir="src_dir"/>
|
2004-12-10 13:17:51 +00:00
|
|
|
<globmapper from="*" to="*.bak"/>
|
2001-02-13 12:32:01 +00:00
|
|
|
</copy>
|
|
|
|
</pre>
|
2001-08-30 13:23:14 +00:00
|
|
|
|
2002-04-01 03:49:51 +00:00
|
|
|
<p><b>Copy a set of files to a directory, replacing @TITLE@ with Foo Bar
|
|
|
|
in all files.</b></p>
|
2001-08-30 13:23:14 +00:00
|
|
|
<pre>
|
2002-09-04 11:05:19 +00:00
|
|
|
<copy todir="../backup/dir">
|
|
|
|
<fileset dir="src_dir"/>
|
2001-08-30 13:23:14 +00:00
|
|
|
<filterset>
|
2002-09-04 11:05:19 +00:00
|
|
|
<filter token="TITLE" value="Foo Bar"/>
|
2001-08-30 13:23:14 +00:00
|
|
|
</filterset>
|
|
|
|
</copy>
|
|
|
|
</pre>
|
|
|
|
|
2005-09-28 18:42:46 +00:00
|
|
|
<p><b>Collect all items from the current CLASSPATH setting into a
|
|
|
|
destination directory, flattening the directory structure.</b></p>
|
|
|
|
<pre>
|
|
|
|
<copy todir="dest" flatten="true">
|
|
|
|
<path>
|
|
|
|
<pathelement path="${java.class.path}"/>
|
|
|
|
</path>
|
|
|
|
</copy>
|
|
|
|
</pre>
|
|
|
|
|
2002-04-01 03:49:51 +00:00
|
|
|
<p><strong>Unix Note:</strong> File permissions are not retained when files
|
2002-04-14 16:36:23 +00:00
|
|
|
are copied; they end up with the default <code>UMASK</code> permissions
|
|
|
|
instead. This
|
2001-12-04 03:06:04 +00:00
|
|
|
is caused by the lack of any means to query or set file permissions in the
|
2002-04-01 03:49:51 +00:00
|
|
|
current Java runtimes. If you need a permission-preserving copy function,
|
2002-06-01 12:26:43 +00:00
|
|
|
use <code><exec executable="cp" ... ></code> instead.
|
2002-04-14 16:36:23 +00:00
|
|
|
</p>
|
2001-08-30 13:23:14 +00:00
|
|
|
|
2002-04-14 16:36:23 +00:00
|
|
|
<p><strong>Windows Note:</strong> If you copy a file to a directory
|
|
|
|
where that file already exists, but with different casing,
|
|
|
|
the copied file takes on the case of the original. The workaround is to
|
|
|
|
<a href="delete.html">delete</a>
|
|
|
|
the file in the destination directory before you copy it.
|
|
|
|
</p>
|
|
|
|
|
2005-01-10 08:37:07 +00:00
|
|
|
<hr><p align="center">Copyright © 2000-2005 The Apache Software Foundation.
|
2002-04-01 03:49:51 +00:00
|
|
|
All rights Reserved.</p>
|
2001-02-13 12:32:01 +00:00
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|