1 | <html>
|
---|
2 |
|
---|
3 | <head>
|
---|
4 | <meta http-equiv="Content-Language" content="en-us">
|
---|
5 | <title>Copy Task</title>
|
---|
6 | <link rel="stylesheet" type="text/css" href="../stylesheets/antmanual.css">
|
---|
7 | </head>
|
---|
8 |
|
---|
9 | <body>
|
---|
10 |
|
---|
11 | <h2><a name="copy">Copy</a></h2>
|
---|
12 | <h3>Description</h3>
|
---|
13 | <p>Copies a file or FileSet to a new file or directory. By default, files are
|
---|
14 | only copied if the source file is newer than the destination file,
|
---|
15 | or when the destination file does not exist. However, you can explicitly
|
---|
16 | overwrite files with the <code>overwrite</code> attribute.</p>
|
---|
17 |
|
---|
18 | <p><a href="../CoreTypes/fileset.html">FileSet</a>s are used to select a
|
---|
19 | set of files to copy.
|
---|
20 | To use a <code><fileset></code>, the <code>todir</code> attribute
|
---|
21 | must be set.</p>
|
---|
22 |
|
---|
23 | <p>
|
---|
24 | <strong>Note: </strong>If you employ filters in your copy operation, you should
|
---|
25 | limit the copy to text files. Binary files will be corrupted by the copy operation.
|
---|
26 | This applies whether the filters are implicitly defined by the
|
---|
27 | <a href="filter.html">filter</a> task or explicitly provided to the copy
|
---|
28 | operation as <a href="../CoreTypes/filterset.html">filtersets</a>
|
---|
29 | </p>
|
---|
30 |
|
---|
31 | <h3>Parameters</h3>
|
---|
32 | <table border="1" cellpadding="2" cellspacing="0">
|
---|
33 | <tr>
|
---|
34 | <td valign="top"><b>Attribute</b></td>
|
---|
35 | <td valign="top"><b>Description</b></td>
|
---|
36 | <td align="center" valign="top"><b>Required</b></td>
|
---|
37 | </tr>
|
---|
38 | <tr>
|
---|
39 | <td valign="top">file</td>
|
---|
40 | <td valign="top">The file to copy.</td>
|
---|
41 | <td valign="top" align="center">Yes, unless a nested
|
---|
42 | <code><fileset></code> element is used.</td>
|
---|
43 | </tr>
|
---|
44 | <tr>
|
---|
45 | <td valign="top">preservelastmodified</td>
|
---|
46 | <td valign="top">Give the copied files the same last modified
|
---|
47 | time as the original source files.
|
---|
48 | (<em>Note</em>: Ignored on Java 1.1)</td>
|
---|
49 | <td valign="top" align="center">No; defaults to false.</td>
|
---|
50 | </tr>
|
---|
51 | <tr>
|
---|
52 | <td valign="top">tofile</td>
|
---|
53 | <td valign="top">The file to copy to.</td>
|
---|
54 | <td valign="top" align="center" rowspan="2">With the <code>file</code>
|
---|
55 | attribute, either <code>tofile</code> or <code>todir</code> can be used.
|
---|
56 | With nested <code><fileset></code> elements, if the set of files
|
---|
57 | is greater than 1, or if only the <code>dir</code> attribute is
|
---|
58 | specified in the <code><fileset></code>, or if the
|
---|
59 | <code>file</code> attribute is also specified, then only
|
---|
60 | <code>todir</code> is allowed.</td>
|
---|
61 | </tr>
|
---|
62 | <tr>
|
---|
63 | <td valign="top">todir</td>
|
---|
64 | <td valign="top">The directory to copy to.</td>
|
---|
65 | </tr>
|
---|
66 | <tr>
|
---|
67 | <td valign="top">overwrite</td>
|
---|
68 | <td valign="top">Overwrite existing files even if the destination
|
---|
69 | files are newer.</td>
|
---|
70 | <td valign="top" align="center">No; defaults to false.</td>
|
---|
71 | </tr>
|
---|
72 | <tr>
|
---|
73 | <td valign="top">filtering</td>
|
---|
74 | <td valign="top">Indicates whether token filtering using the global
|
---|
75 | build-file filters should take place during the copy.
|
---|
76 | <em>Note</em>: Nested <code><filterset></code> elements will
|
---|
77 | always be used, even if this attribute is not specified, or its value is
|
---|
78 | <code>false</code> (<code>no</code>, or <code>off</code>).</td>
|
---|
79 | <td valign="top" align="center">No; defaults to false.</td>
|
---|
80 | </tr>
|
---|
81 | <tr>
|
---|
82 | <td valign="top">flatten</td>
|
---|
83 | <td valign="top">Ignore the directory structure of the source files,
|
---|
84 | and copy all files into the directory specified by the <code>todir</code>
|
---|
85 | attribute. Note that you can achieve the same effect by using a
|
---|
86 | <a href="../CoreTypes/mapper.html#flatten-mapper">flatten mapper</a>.</td>
|
---|
87 | <td valign="top" align="center">No; defaults to false.</td>
|
---|
88 | </tr>
|
---|
89 | <tr>
|
---|
90 | <td valign="top">includeEmptyDirs</td>
|
---|
91 | <td valign="top">Copy any empty directories included in the FileSet(s).
|
---|
92 | </td>
|
---|
93 | <td valign="top" align="center">No; defaults to true.</td>
|
---|
94 | </tr>
|
---|
95 | <tr>
|
---|
96 | <td valign="top">failonerror</td>
|
---|
97 | <td valign="top">Log a warning message, but do not stop the
|
---|
98 | build, when the file to copy does not exist or one of the nested
|
---|
99 | filesets points to a directory that doesn't exist or an error occurs
|
---|
100 | while copying.
|
---|
101 | </td>
|
---|
102 | <td valign="top" align="center">No; defaults to true.</td>
|
---|
103 | </tr>
|
---|
104 | <tr>
|
---|
105 | <td valign="top">verbose</td>
|
---|
106 | <td valign="top">Log the files that are being copied.</td>
|
---|
107 | <td valign="top" align="center">No; defaults to false.</td>
|
---|
108 | </tr>
|
---|
109 | <tr>
|
---|
110 | <td valign="top">encoding</td>
|
---|
111 | <td valign="top">The encoding to assume when filter-copying the
|
---|
112 | files. <em>since Ant 1.5</em>.</td>
|
---|
113 | <td align="center">No - defaults to default JVM encoding</td>
|
---|
114 | </tr>
|
---|
115 | <tr>
|
---|
116 | <td valign="top">outputencoding</td>
|
---|
117 | <td valign="top">The encoding to use when writing the files.
|
---|
118 | <em>since Ant 1.6</em>.</td>
|
---|
119 | <td align="center">No - defaults to the value of the encoding
|
---|
120 | attribute if given or the default JVM encoding otherwise.</td>
|
---|
121 | </tr>
|
---|
122 | <tr>
|
---|
123 | <td valign="top">enablemultiplemappings</td>
|
---|
124 | <td valign="top">
|
---|
125 | If true the task will process to all the mappings for a
|
---|
126 | given source path. If false the task will only process
|
---|
127 | the first file or directory. This attribute is only relevant
|
---|
128 | if there is a mapper subelement.
|
---|
129 | <em>since Ant 1.6</em>.</td>
|
---|
130 | <td align="center">No - defaults to false.</td>
|
---|
131 | </tr>
|
---|
132 | <tr>
|
---|
133 | <td valign="top">granularity</td>
|
---|
134 | <td valign="top">The number of milliseconds leeway to give before
|
---|
135 | deciding a file is out of date. This is needed because not every
|
---|
136 | file system supports tracking the last modified time to the
|
---|
137 | millisecond level. Default is 0 milliseconds, or 2 seconds on DOS
|
---|
138 | systems. This can also be useful if source and target files live
|
---|
139 | on separate machines with clocks being out of sync. <em>since Ant
|
---|
140 | 1.6.2</em>.</td>
|
---|
141 | </tr>
|
---|
142 | </table>
|
---|
143 | <h3>Parameters specified as nested elements</h3>
|
---|
144 |
|
---|
145 | <h4>fileset</h4>
|
---|
146 | <p><a href="../CoreTypes/fileset.html">FileSet</a>s are used to select
|
---|
147 | sets of files to copy.
|
---|
148 | To use a fileset, the <code>todir</code> attribute must be set.</p>
|
---|
149 |
|
---|
150 | <h4>mapper</h4>
|
---|
151 | <p>You can define filename transformations by using a nested <a
|
---|
152 | href="../CoreTypes/mapper.html">mapper</a> element. The default mapper used by
|
---|
153 | <code><copy></code> is the <a
|
---|
154 | href="../CoreTypes/mapper.html#identity-mapper">identity mapper</a>.</p>
|
---|
155 |
|
---|
156 | <h4>filterset</h4>
|
---|
157 | <p><a href="../CoreTypes/filterset.html">FilterSet</a>s are used to replace
|
---|
158 | tokens in files that are copied.
|
---|
159 | To use a FilterSet, use the nested <code><filterset></code> element.</p>
|
---|
160 |
|
---|
161 | <h4>filterchain</h4>
|
---|
162 | <p>The Copy task supports nested <a href="../CoreTypes/filterchain.html">
|
---|
163 | FilterChain</a>s.</p>
|
---|
164 |
|
---|
165 | <p>
|
---|
166 | If <filterset> and <filterchain> elements are used inside the
|
---|
167 | same <copy> task, all <filterchain> elements are processed first
|
---|
168 | followed by <filterset> elements.
|
---|
169 | </p>
|
---|
170 |
|
---|
171 | <h3>Examples</h3>
|
---|
172 | <p><b>Copy a single file</b></p>
|
---|
173 | <pre>
|
---|
174 | <copy file="myfile.txt" tofile="mycopy.txt"/>
|
---|
175 | </pre>
|
---|
176 | <p><b>Copy a single file to a directory</b></p>
|
---|
177 | <pre>
|
---|
178 | <copy file="myfile.txt" todir="../some/other/dir"/>
|
---|
179 | </pre>
|
---|
180 | <p><b>Copy a directory to another directory</b></p>
|
---|
181 | <pre>
|
---|
182 | <copy todir="../new/dir">
|
---|
183 | <fileset dir="src_dir"/>
|
---|
184 | </copy>
|
---|
185 | </pre>
|
---|
186 | <p><b>Copy a set of files to a directory</b></p>
|
---|
187 | <pre>
|
---|
188 | <copy todir="../dest/dir">
|
---|
189 | <fileset dir="src_dir">
|
---|
190 | <exclude name="**/*.java"/>
|
---|
191 | </fileset>
|
---|
192 | </copy>
|
---|
193 |
|
---|
194 | <copy todir="../dest/dir">
|
---|
195 | <fileset dir="src_dir" excludes="**/*.java"/>
|
---|
196 | </copy>
|
---|
197 | </pre>
|
---|
198 | <p><b>Copy a set of files to a directory, appending
|
---|
199 | <code>.bak</code> to the file name on the fly</b></p>
|
---|
200 | <pre>
|
---|
201 | <copy todir="../backup/dir">
|
---|
202 | <fileset dir="src_dir"/>
|
---|
203 | <mapper type="glob" from="*" to="*.bak"/>
|
---|
204 | </copy>
|
---|
205 | </pre>
|
---|
206 |
|
---|
207 |
|
---|
208 | <p><b>Copy a set of files to a directory, replacing @TITLE@ with Foo Bar
|
---|
209 | in all files.</b></p>
|
---|
210 | <pre>
|
---|
211 | <copy todir="../backup/dir">
|
---|
212 | <fileset dir="src_dir"/>
|
---|
213 | <filterset>
|
---|
214 | <filter token="TITLE" value="Foo Bar"/>
|
---|
215 | </filterset>
|
---|
216 | </copy>
|
---|
217 | </pre>
|
---|
218 |
|
---|
219 | <p><strong>Unix Note:</strong> File permissions are not retained when files
|
---|
220 | are copied; they end up with the default <code>UMASK</code> permissions
|
---|
221 | instead. This
|
---|
222 | is caused by the lack of any means to query or set file permissions in the
|
---|
223 | current Java runtimes. If you need a permission-preserving copy function,
|
---|
224 | use <code><exec executable="cp" ... ></code> instead.
|
---|
225 | </p>
|
---|
226 |
|
---|
227 | <p><strong>Windows Note:</strong> If you copy a file to a directory
|
---|
228 | where that file already exists, but with different casing,
|
---|
229 | the copied file takes on the case of the original. The workaround is to
|
---|
230 | <a href="delete.html">delete</a>
|
---|
231 | the file in the destination directory before you copy it.
|
---|
232 | </p>
|
---|
233 |
|
---|
234 | <hr><p align="center">Copyright © 2000-2004 The Apache Software Foundation.
|
---|
235 | All rights Reserved.</p>
|
---|
236 |
|
---|
237 | </body>
|
---|
238 | </html>
|
---|
239 |
|
---|