You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

copy.html 8.9 KiB

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