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 6.9 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. <h3>Parameters</h3>
  18. <table border="1" cellpadding="2" cellspacing="0">
  19. <tr>
  20. <td valign="top"><b>Attribute</b></td>
  21. <td valign="top"><b>Description</b></td>
  22. <td align="center" valign="top"><b>Required</b></td>
  23. </tr>
  24. <tr>
  25. <td valign="top">file</td>
  26. <td valign="top">The file to copy.</td>
  27. <td valign="top" align="center">Yes, unless a nested
  28. <code>&lt;fileset&gt;</code> element is used.</td>
  29. </tr>
  30. <tr>
  31. <td valign="top">preservelastmodified</td>
  32. <td valign="top">Give the copied files the same last modified
  33. time as the original source files.
  34. (<em>Note</em>: Ignored on Java 1.1)</td>
  35. <td valign="top" align="center">No; defaults to false.</td>
  36. </tr>
  37. <tr>
  38. <td valign="top">tofile</td>
  39. <td valign="top">The file to copy to.</td>
  40. <td valign="top" align="center" rowspan="2">With the <code>file</code>
  41. attribute, either <code>tofile</code> or <code>todir</code> can be used.
  42. With nested <code>&lt;fileset&gt;</code> elements, if the set of files
  43. is greater than 1, or if only the <code>dir</code> attribute is
  44. specified in the <code>&lt;fileset&gt;</code>, or if the
  45. <code>file</code> attribute is also specified, then only
  46. <code>todir</code> is allowed.</td>
  47. </tr>
  48. <tr>
  49. <td valign="top">todir</td>
  50. <td valign="top">The directory to copy to.</td>
  51. </tr>
  52. <tr>
  53. <td valign="top">overwrite</td>
  54. <td valign="top">Overwrite existing files even if the destination
  55. files are newer.</td>
  56. <td valign="top" align="center">No; defaults to false.</td>
  57. </tr>
  58. <tr>
  59. <td valign="top">filtering</td>
  60. <td valign="top">Indicates whether token filtering using the global
  61. build-file filters should take place during the copy.
  62. <em>Note</em>: Nested <code>&lt;filterset&gt;</code> elements will
  63. always be used, even if this attribute is not specified, or its value is
  64. <code>false</code> (<code>no</code>, or <code>off</code>).</td>
  65. <td valign="top" align="center">No; defaults to false.</td>
  66. </tr>
  67. <tr>
  68. <td valign="top">flatten</td>
  69. <td valign="top">Ignore the directory structure of the source files,
  70. and copy all files into the directory specified by the <code>todir</code>
  71. attribute. Note that you can achieve the same effect by using a
  72. <a href="../CoreTypes/mapper.html#flatten-mapper">flatten mapper</a>.</td>
  73. <td valign="top" align="center">No; defaults to false.</td>
  74. </tr>
  75. <tr>
  76. <td valign="top">includeEmptyDirs</td>
  77. <td valign="top">Copy any empty directories included in the FileSet(s).
  78. </td>
  79. <td valign="top" align="center">No; defaults to true.</td>
  80. </tr>
  81. <tr>
  82. <td valign="top">failonerror</td>
  83. <td valign="top">Log a warning message, but do not stop the build,
  84. when the file to copy does not exist.
  85. Only meaningful when copying a single file.
  86. </td>
  87. <td valign="top" align="center">No; defaults to true.</td>
  88. </tr>
  89. <tr>
  90. <td valign="top">verbose</td>
  91. <td valign="top">Log the files that are being copied.</td>
  92. <td valign="top" align="center">No; defaults to false.</td>
  93. </tr>
  94. </table>
  95. <h3>Parameters specified as nested elements</h3>
  96. <h4>fileset</h4>
  97. <p><a href="../CoreTypes/fileset.html">FileSet</a>s are used to select
  98. sets of files to copy.
  99. To use a fileset, the <code>todir</code> attribute must be set.</p>
  100. <h4>mapper</h4>
  101. <p>You can define filename transformations by using a nested <a
  102. href="../CoreTypes/mapper.html">mapper</a> element. The default mapper used by
  103. <code>&lt;copy&gt;</code> is the <a
  104. href="../CoreTypes/mapper.html#identity-mapper">identity mapper</a>.</p>
  105. <h4>filterset</h4>
  106. <p><a href="../CoreTypes/filterset.html">FilterSet</a>s are used to replace
  107. tokens in files that are copied.
  108. To use a FilterSet, use the nested <code>&lt;filterset&gt;</code> element.</p>
  109. <h4>filterchain</h4>
  110. <p>The Copy task supports nested <a href="../CoreTypes/filterchain.html">
  111. FilterChain</a>s.</p>
  112. <p>
  113. If &lt;filterset&gt; and &lt;filterchain&gt; elements are used inside the
  114. same &lt;copy&gt; task, all &lt;filterchain&gt; elements are processed first
  115. followed by &lt;filterset&gt; elements.
  116. </p>
  117. <h3>Examples</h3>
  118. <p><b>Copy a single file</b></p>
  119. <pre>
  120. &lt;copy file=&quot;myfile.txt&quot; tofile=&quot;mycopy.txt&quot;/&gt;
  121. </pre>
  122. <p><b>Copy a single file to a directory</b></p>
  123. <pre>
  124. &lt;copy file=&quot;myfile.txt&quot; todir=&quot;../some/other/dir&quot;/&gt;
  125. </pre>
  126. <p><b>Copy a directory to another directory</b></p>
  127. <pre>
  128. &lt;copy todir=&quot;../new/dir&quot;&gt;
  129. &lt;fileset dir=&quot;src_dir&quot;/&gt;
  130. &lt;/copy&gt;
  131. </pre>
  132. <p><b>Copy a set of files to a directory</b></p>
  133. <pre>
  134. &lt;copy todir=&quot;../dest/dir&quot; &gt;
  135. &lt;fileset dir=&quot;src_dir&quot; &gt;
  136. &lt;exclude name=&quot;**/*.java&quot;/&gt;
  137. &lt;/fileset&gt;
  138. &lt;/copy&gt;
  139. &lt;copy todir=&quot;../dest/dir&quot; &gt;
  140. &lt;fileset dir=&quot;src_dir&quot; excludes=&quot;**/*.java&quot;/&gt;
  141. &lt;/copy&gt;
  142. </pre>
  143. <p><b>Copy a set of files to a directory, appending
  144. <code>.bak</code> to the file name on the fly</b></p>
  145. <pre>
  146. &lt;copy todir=&quot;../backup/dir&quot; &gt;
  147. &lt;fileset dir=&quot;src_dir&quot; /&gt;
  148. &lt;mapper type=&quot;glob&quot; from=&quot;*&quot; to=&quot;*.bak&quot;/&gt;
  149. &lt;/copy&gt;
  150. </pre>
  151. <p><b>Copy a set of files to a directory, replacing @TITLE@ with Foo Bar
  152. in all files.</b></p>
  153. <pre>
  154. &lt;copy todir=&quot;../backup/dir&quot; &gt;
  155. &lt;fileset dir=&quot;src_dir&quot; /&gt;
  156. &lt;filterset&gt;
  157. &lt;filter token=&quot;TITLE&quot; value=&quot;Foo Bar&quot; /&gt;
  158. &lt;/filterset&gt;
  159. &lt;/copy&gt;
  160. </pre>
  161. <p><strong>Unix Note:</strong> File permissions are not retained when files
  162. are copied; they end up with the default <code>UMASK</code> permissions
  163. instead. This
  164. is caused by the lack of any means to query or set file permissions in the
  165. current Java runtimes. If you need a permission-preserving copy function,
  166. use <code>&lt;exec executable="cp" ... &gt;</code> instead.
  167. </p>
  168. <p><strong>Windows Note:</strong> If you copy a file to a directory
  169. where that file already exists, but with different casing,
  170. the copied file takes on the case of the original. The workaround is to
  171. <a href="delete.html">delete</a>
  172. the file in the destination directory before you copy it.
  173. </p>
  174. <hr><p align="center">Copyright &copy; 2000-2002 Apache Software Foundation.
  175. All rights Reserved.</p>
  176. </body>
  177. </html>