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.

subant.html 20 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <title>Subant
  5. Task</title>
  6. </head>
  7. <body bgcolor="#ffffff" text="#000000" link="#525D76"
  8. alink="#525D76" vlink="#525D76">
  9. <table border="0" width="100%" cellspacing="4">
  10. <!-- PAGE HEADER -->
  11. <tr>
  12. <td>
  13. <table border="0" width="100%"><tr>
  14. <td valign="bottom">
  15. <font size="+3" face="arial,helvetica,sanserif"><strong>Subant
  16. Task</strong></font>
  17. <br><font face="arial,helvetica,sanserif">Calls a given target for all defined sub-builds.</font>
  18. </td>
  19. <td>
  20. <!-- PROJECT LOGO -->
  21. <a href="http://ant.apache.org/">
  22. <img src="../../images/ant_logo_large.gif" align="right" alt="Apache Ant" border="0">
  23. </a>
  24. </td>
  25. </tr></table>
  26. </td>
  27. </tr>
  28. <!-- START RIGHT SIDE MAIN BODY -->
  29. <tr>
  30. <td valign="top" align="left">
  31. <!-- Applying task/description -->
  32. <!-- Start Description -->
  33. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  34. <tr><td>&nbsp;</td></tr>
  35. <tr><td bgcolor="#525D76">
  36. <font color="#ffffff" face="arial,helvetica.sanserif">
  37. <a name="description">
  38. <strong>Description</strong></a></font>
  39. </td></tr>
  40. <tr><td><blockquote>
  41. <p>
  42. Calls a given target for all defined sub-builds.
  43. This is an extension
  44. of ant for bulk project execution.
  45. <strong>This task must not be used outside of a
  46. <code>target</code> if it invokes the same build file it is
  47. part of.</strong>
  48. </p>
  49. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  50. <!-- Subsection heading -->
  51. <tr><td bgcolor="#828DA6">
  52. <font color="#ffffff" face="arial,helvetica.sanserif">
  53. <a name="Use with directories">
  54. <strong>Use with directories</strong></a></font>
  55. </td></tr>
  56. <!-- Subsection body -->
  57. <tr><td>
  58. <p>
  59. subant can be used with directory sets to execute a build from different directories.
  60. 2 different options are offered :
  61. </p>
  62. <ul>
  63. <li>
  64. to run the same build file <code>/somepath/otherpath/mybuild.xml</code>
  65. with different base directories, use the genericantfile attribute
  66. </li>
  67. <li>if you want to run <code>directory1/mybuild.xml</code>, <code>directory2/mybuild.xml</code>, <code>....</code>,
  68. use the antfile attribute. The subant task does not set the base directory for you in this case, because you can specify it in each build file.
  69. </li>
  70. </ul>
  71. </td></tr>
  72. </table>
  73. </blockquote></td></tr>
  74. </table>
  75. <!-- End Description -->
  76. <!-- Ignore -->
  77. <!-- Start Attributes -->
  78. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  79. <tr><td>&nbsp;</td></tr>
  80. <tr><td bgcolor="#525D76">
  81. <font color="#ffffff" face="arial,helvetica.sanserif">
  82. <a name="attributes">
  83. <strong>Parameters</strong></a></font>
  84. </td></tr>
  85. <tr><td><blockquote>
  86. <table>
  87. <tr>
  88. <td bgcolor="#cccccc" valign="top" align="left">
  89. <font color="#000000" size="-1" face="arial,helvetica,sanserif"><b>Attribute</b></font>
  90. </td>
  91. <td bgcolor="#cccccc" valign="top" align="left">
  92. <font color="#000000" size="-1" face="arial,helvetica,sanserif"><b>Description</b></font>
  93. </td>
  94. <td bgcolor="#cccccc" valign="top" align="left">
  95. <font color="#000000" size="-1" face="arial,helvetica,sanserif"><b>Type</b></font>
  96. </td>
  97. <td bgcolor="#cccccc" valign="top" align="left">
  98. <font color="#000000" size="-1" face="arial,helvetica,sanserif"><b>Requirement</b></font>
  99. </td>
  100. </tr>
  101. <!-- Attribute Group -->
  102. <!-- Attribute Group -->
  103. <!-- Attribute -->
  104. <tr>
  105. <td bgcolor="#eeeeee" valign="top" align="left">
  106. <font color="#000000" size="-1" face="arial,helvetica,sanserif">antfile</font>
  107. </td>
  108. <td bgcolor="#eeeeee" valign="top" align="left">
  109. <font color="#000000" size="-1" face="arial,helvetica,sanserif">Build file name, to use in conjunction with directories.<br> Defaults to "build.xml".<br> If <code>genericantfile</code> is set, this attribute is ignored.</font>
  110. </td>
  111. <td bgcolor="#eeeeee" valign="top" align="left">
  112. <font color="#000000" size="-1" face="arial,helvetica,sanserif">String</font>
  113. </td>
  114. <td bgcolor="#eeeeee" valign="top" align="left" rowspan="10">
  115. <font color="#000000" size="-1" face="arial,helvetica,sanserif">Optional</font>
  116. </td>
  117. </tr>
  118. <!-- Attribute -->
  119. <tr>
  120. <td bgcolor="#eeeeee" valign="top" align="left">
  121. <font color="#000000" size="-1" face="arial,helvetica,sanserif">buildpath</font>
  122. </td>
  123. <td bgcolor="#eeeeee" valign="top" align="left">
  124. <font color="#000000" size="-1" face="arial,helvetica,sanserif">Set the buildpath to be used to find sub-projects.</font>
  125. </td>
  126. <td bgcolor="#eeeeee" valign="top" align="left">
  127. <font color="#000000" size="-1" face="arial,helvetica,sanserif">Path</font>
  128. </td>
  129. </tr>
  130. <!-- Attribute -->
  131. <tr>
  132. <td bgcolor="#eeeeee" valign="top" align="left">
  133. <font color="#000000" size="-1" face="arial,helvetica,sanserif">buildpathref</font>
  134. </td>
  135. <td bgcolor="#eeeeee" valign="top" align="left">
  136. <font color="#000000" size="-1" face="arial,helvetica,sanserif">Buildpath to use, by reference.</font>
  137. </td>
  138. <td bgcolor="#eeeeee" valign="top" align="left">
  139. <font color="#000000" size="-1" face="arial,helvetica,sanserif">Reference</font>
  140. </td>
  141. </tr>
  142. <!-- Attribute -->
  143. <tr>
  144. <td bgcolor="#eeeeee" valign="top" align="left">
  145. <font color="#000000" size="-1" face="arial,helvetica,sanserif">failonerror</font>
  146. </td>
  147. <td bgcolor="#eeeeee" valign="top" align="left">
  148. <font color="#000000" size="-1" face="arial,helvetica,sanserif">Sets whether to fail with a build exception on error, or go on.</font>
  149. </td>
  150. <td bgcolor="#eeeeee" valign="top" align="left">
  151. <font color="#000000" size="-1" face="arial,helvetica,sanserif">boolean</font>
  152. </td>
  153. </tr>
  154. <!-- Attribute -->
  155. <tr>
  156. <td bgcolor="#eeeeee" valign="top" align="left">
  157. <font color="#000000" size="-1" face="arial,helvetica,sanserif">genericantfile</font>
  158. </td>
  159. <td bgcolor="#eeeeee" valign="top" align="left">
  160. <font color="#000000" size="-1" face="arial,helvetica,sanserif">Build file path, to use in conjunction with directories.<br> Use <code>genericantfile</code>, in order to run the same build file with different basedirs.<br> If this attribute is set, <code>antfile</code> is ignored.</font>
  161. </td>
  162. <td bgcolor="#eeeeee" valign="top" align="left">
  163. <font color="#000000" size="-1" face="arial,helvetica,sanserif">File</font>
  164. </td>
  165. </tr>
  166. <!-- Attribute -->
  167. <tr>
  168. <td bgcolor="#eeeeee" valign="top" align="left">
  169. <font color="#000000" size="-1" face="arial,helvetica,sanserif">inheritall</font>
  170. </td>
  171. <td bgcolor="#eeeeee" valign="top" align="left">
  172. <font color="#000000" size="-1"
  173. face="arial,helvetica,sanserif">Corresponds to
  174. <code>&lt;ant&gt;</code>'s
  175. <code>inheritall</code> attribute but defaults
  176. to false in this task..</font>
  177. </td>
  178. <td bgcolor="#eeeeee" valign="top" align="left">
  179. <font color="#000000" size="-1" face="arial,helvetica,sanserif">boolean</font>
  180. </td>
  181. </tr>
  182. <!-- Attribute -->
  183. <tr>
  184. <td bgcolor="#eeeeee" valign="top" align="left">
  185. <font color="#000000" size="-1" face="arial,helvetica,sanserif">inheritrefs</font>
  186. </td>
  187. <td bgcolor="#eeeeee" valign="top" align="left">
  188. <font color="#000000" size="-1" face="arial,helvetica,sanserif">Corresponds to <code>&lt;ant&gt;</code>'s <code>inheritrefs</code> attribute.</font>
  189. </td>
  190. <td bgcolor="#eeeeee" valign="top" align="left">
  191. <font color="#000000" size="-1" face="arial,helvetica,sanserif">boolean</font>
  192. </td>
  193. </tr>
  194. <!-- Attribute -->
  195. <tr>
  196. <td bgcolor="#eeeeee" valign="top" align="left">
  197. <font color="#000000" size="-1" face="arial,helvetica,sanserif">output</font>
  198. </td>
  199. <td bgcolor="#eeeeee" valign="top" align="left">
  200. <font color="#000000" size="-1" face="arial,helvetica,sanserif">Corresponds to <code>&lt;ant&gt;</code>'s <code>output</code> attribute.</font>
  201. </td>
  202. <td bgcolor="#eeeeee" valign="top" align="left">
  203. <font color="#000000" size="-1" face="arial,helvetica,sanserif">String</font>
  204. </td>
  205. </tr>
  206. <!-- Attribute -->
  207. <tr>
  208. <td bgcolor="#eeeeee" valign="top" align="left">
  209. <font color="#000000" size="-1" face="arial,helvetica,sanserif">target</font>
  210. </td>
  211. <td bgcolor="#eeeeee" valign="top" align="left">
  212. <font color="#000000" size="-1" face="arial,helvetica,sanserif"></font>
  213. </td>
  214. <td bgcolor="#eeeeee" valign="top" align="left">
  215. <font color="#000000" size="-1" face="arial,helvetica,sanserif">String</font>
  216. </td>
  217. </tr>
  218. <!-- Attribute -->
  219. <tr>
  220. <td bgcolor="#eeeeee" valign="top" align="left">
  221. <font color="#000000" size="-1" face="arial,helvetica,sanserif">verbose</font>
  222. </td>
  223. <td bgcolor="#eeeeee" valign="top" align="left">
  224. <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  225. Enable/ disable log messages showing when each sub-build path is entered/ exited.
  226. The default value is false.</font>
  227. </td>
  228. <td bgcolor="#eeeeee" valign="top" align="left">
  229. <font color="#000000" size="-1" face="arial,helvetica,sanserif">boolean</font>
  230. </td>
  231. </tr>
  232. </table>
  233. </blockquote></td></tr>
  234. </table>
  235. <!-- End Attributes -->
  236. <!-- Start Elements -->
  237. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  238. <tr><td>&nbsp;</td></tr>
  239. <tr><td bgcolor="#525D76">
  240. <font color="#ffffff" face="arial,helvetica.sanserif">
  241. <a name="elements">
  242. <strong>Parameters as nested elements</strong></a></font>
  243. </td></tr>
  244. <tr><td><blockquote>
  245. <!-- Start Element -->
  246. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  247. <tr><td>&nbsp;</td></tr>
  248. <tr><td bgcolor="#828DA6">
  249. <font color="#ffffff" face="arial,helvetica.sanserif" size="-1">
  250. <strong>any filesystem based <a href="../CoreTypes/resources.html#collection">resource collection</a></strong></font>
  251. </td></tr>
  252. <tr><td><blockquote>
  253. This includes <code>&lt;fileset&gt;</code>,
  254. <code>&lt;dirset&gt;</code> and <code>&lt;filelist&gt;</code>
  255. which are the nested resource collections supported prior
  256. to Ant 1.7.
  257. <!-- Ignore -->
  258. <!-- Ignore -->
  259. </blockquote></td></tr>
  260. </table>
  261. <!-- End Element -->
  262. <!-- Start Element -->
  263. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  264. <tr><td>&nbsp;</td></tr>
  265. <tr><td bgcolor="#828DA6">
  266. <font color="#ffffff" face="arial,helvetica.sanserif" size="-1">
  267. <strong>dirset</strong> (org.apache.tools.ant.types.DirSet)</font>
  268. </td></tr>
  269. <tr><td><blockquote>
  270. Adds a directory set to the implicit build path. <p> <em>Note that the directories will be added to the build path in no particular order, so if order is significant, one should use a file list instead!</em>
  271. <!-- Ignore -->
  272. <!-- Ignore -->
  273. </blockquote></td></tr>
  274. </table>
  275. <!-- End Element -->
  276. <!-- Start Element -->
  277. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  278. <tr><td>&nbsp;</td></tr>
  279. <tr><td bgcolor="#828DA6">
  280. <font color="#ffffff" face="arial,helvetica.sanserif" size="-1">
  281. <strong>filelist</strong> (org.apache.tools.ant.types.FileList)</font>
  282. </td></tr>
  283. <tr><td><blockquote>
  284. Adds an ordered file list to the implicit build path. <p> <em>Note that contrary to file and directory sets, file lists can reference non-existent files or directories!</em>
  285. <!-- Ignore -->
  286. <!-- Ignore -->
  287. </blockquote></td></tr>
  288. </table>
  289. <!-- End Element -->
  290. <!-- Start Element -->
  291. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  292. <tr><td>&nbsp;</td></tr>
  293. <tr><td bgcolor="#828DA6">
  294. <font color="#ffffff" face="arial,helvetica.sanserif" size="-1">
  295. <strong>fileset</strong> (org.apache.tools.ant.types.FileSet)</font>
  296. </td></tr>
  297. <tr><td><blockquote>
  298. Adds a file set to the implicit build path. <p> <em>Note that the directories will be added to the build path in no particular order, so if order is significant, one should use a file list instead!</em>
  299. <!-- Ignore -->
  300. <!-- Ignore -->
  301. </blockquote></td></tr>
  302. </table>
  303. <!-- End Element -->
  304. <!-- Start Element -->
  305. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  306. <tr><td>&nbsp;</td></tr>
  307. <tr><td bgcolor="#828DA6">
  308. <font color="#ffffff" face="arial,helvetica.sanserif" size="-1">
  309. <strong>property</strong> (org.apache.tools.ant.taskdefs.Property)</font>
  310. </td></tr>
  311. <tr><td><blockquote>
  312. Corresponds to <code>&lt;ant&gt;</code>'s nested <code>&lt;property&gt;</code> element.
  313. <!-- Ignore -->
  314. <!-- Ignore -->
  315. </blockquote></td></tr>
  316. </table>
  317. <!-- End Element -->
  318. <!-- Start Element -->
  319. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  320. <tr><td>&nbsp;</td></tr>
  321. <tr><td bgcolor="#828DA6">
  322. <font color="#ffffff" face="arial,helvetica.sanserif" size="-1">
  323. <strong>propertyset</strong> (org.apache.tools.ant.types.PropertySet)</font>
  324. </td></tr>
  325. <tr><td><blockquote>
  326. Corresponds to <code>&lt;ant&gt;</code>'s nested <code>&lt;propertyset&gt;</code> element.
  327. <!-- Ignore -->
  328. <!-- Ignore -->
  329. </blockquote></td></tr>
  330. </table>
  331. <!-- End Element -->
  332. <!-- Start Element -->
  333. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  334. <tr><td>&nbsp;</td></tr>
  335. <tr><td bgcolor="#828DA6">
  336. <font color="#ffffff" face="arial,helvetica.sanserif" size="-1">
  337. <strong>buildpath</strong> (org.apache.tools.ant.types.Path)</font>
  338. </td></tr>
  339. <tr><td><blockquote>
  340. Creates a nested build path, and add it to the implicit build path.
  341. <!-- Ignore -->
  342. <!-- Ignore -->
  343. </blockquote></td></tr>
  344. </table>
  345. <!-- End Element -->
  346. <!-- Start Element -->
  347. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  348. <tr><td>&nbsp;</td></tr>
  349. <tr><td bgcolor="#828DA6">
  350. <font color="#ffffff" face="arial,helvetica.sanserif" size="-1">
  351. <strong>buildpathelement</strong> (org.apache.tools.ant.types.Path.PathElement)</font>
  352. </td></tr>
  353. <tr><td><blockquote>
  354. Creates a nested <code>&lt;buildpathelement&gt;</code>, and add it to the implicit build path.
  355. <!-- Ignore -->
  356. <!-- Ignore -->
  357. </blockquote></td></tr>
  358. </table>
  359. <!-- End Element -->
  360. </blockquote></td></tr>
  361. </table>
  362. <!-- End Elements -->
  363. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  364. <tr><td>&nbsp;</td></tr>
  365. <tr><td bgcolor="#525D76">
  366. <font color="#ffffff" face="arial,helvetica.sanserif">
  367. <a name="examples">
  368. <strong>Examples</strong></a></font>
  369. </td></tr>
  370. <tr><td><blockquote>
  371. <pre>
  372. &lt;project name="subant" default="subant1"&gt;
  373. &lt;property name="build.dir" value="subant.build"/&gt;
  374. &lt;target name="subant1"&gt;
  375. &lt;subant target=""&gt;
  376. &lt;property name="build.dir" value="subant1.build"/&gt;
  377. &lt;property name="not.overloaded" value="not.overloaded"/&gt;
  378. &lt;fileset dir="." includes="*/build.xml"/&gt;
  379. &lt;/subant&gt;
  380. &lt;/target&gt;
  381. &lt;/project&gt;
  382. </pre>
  383. <p>
  384. this snippet build file will run ant in each subdirectory of the project directory,
  385. where a file called build.xml can be found.
  386. The property build.dir will have the value subant1.build in the ant projects called by subant.
  387. </p>
  388. <pre>
  389. &lt;subant target=""&gt;
  390. &lt;propertyset&gt;
  391. &lt;propertyref prefix="toplevel"/&gt;
  392. &lt;mapper type="glob" from="foo*" to="bar*"/&gt;
  393. &lt;/propertyset&gt;
  394. &lt;fileset dir="." includes="*/build.xml"/&gt;
  395. &lt;/subant&gt;
  396. </pre>
  397. <p>
  398. this snippet build file will run ant in each subdirectory of the project directory,
  399. where a file called build.xml can be found.
  400. All properties whose name starts with "foo" are passed, their names are changed to start with "bar" instead
  401. </p>
  402. <pre>
  403. &lt;subant target="compile" genericantfile="/opt/project/build1.xml"&gt;
  404. &lt;dirset dir="." includes="projects*"/&gt;
  405. &lt;/subant&gt;
  406. </pre>
  407. <p>
  408. assuming the subdirs of the project dir are called projects1, projects2, projects3
  409. this snippet will execute the compile target of /opt/project/build1.xml,
  410. setting the basedir to projects1, projects2, projects3
  411. </p>
  412. <!-- manually written -->
  413. <p>Now a little more complex - but useful - scenario. Assume that we have
  414. a directory structure like this:</p>
  415. <pre>
  416. root
  417. | common.xml
  418. | build.xml
  419. |
  420. +-- modules
  421. +-- modA
  422. | +-- src
  423. +-- modB
  424. +-- src
  425. <u><b>common.xml:</b></u><br>
  426. &lt;project&gt;
  427. &lt;property name="src.dir" value="src"/&gt;
  428. &lt;property name="build.dir" value="build"/&gt;
  429. &lt;property name="classes.dir" value="${build.dir}/classes"/&gt;
  430. &lt;target name="compile"&gt;
  431. &lt;mkdir dir="${classes.dir}"/&gt;
  432. &lt;javac srcdir="${src.dir}" destdir="${classes.dir}"/&gt;
  433. &lt;/target&gt;
  434. &lt;!-- more targets --&gt;
  435. &lt;/project&gt;
  436. <u><b>build.xml:</b></u><br>
  437. &lt;project&gt;
  438. &lt;macrodef name="iterate"&gt;
  439. &lt;attribute name="target"/&gt;
  440. &lt;sequential&gt;
  441. &lt;subant target="@{target}"&gt;
  442. &lt;fileset dir="modules" includes="*/build.xml"/&gt;
  443. &lt;/subant&gt;
  444. &lt;/sequential&gt;
  445. &lt;/macrodef&gt;
  446. &lt;target name="compile"&gt;
  447. &lt;iterate target="compile"/&gt;
  448. &lt;/target&gt;
  449. &lt;!-- more targets --&gt;
  450. &lt;/project&gt;
  451. <u><b>modules/modA/build.xml:</b></u><br>
  452. &lt;project name="modA"&gt;
  453. &lt;import file="../../common.xml"/&gt;
  454. &lt;/project&gt;
  455. </pre>
  456. <p>This results in very small buildfiles in the modules, maintainable
  457. buildfile (common.xml) and a clear project structure. Additionally
  458. the root buildfile is capable to run the whole build over all
  459. modules.
  460. </p>
  461. <!-- manually written -->
  462. </blockquote></td></tr>
  463. </table>
  464. </td>
  465. </tr>
  466. <!-- END RIGHT SIDE MAIN BODY -->
  467. <!-- FOOTER SEPARATOR -->
  468. <tr>
  469. <td>
  470. <hr noshade="" size="1">
  471. </td>
  472. </tr>
  473. <!-- PAGE FOOTER -->
  474. <tr>
  475. <td>
  476. <div align="center"><font color="#525D76" size="-1"><em>
  477. Copyright &copy; 2000-2005, The Apache Software Foundation. All Rights Reserved.
  478. </em></font></div>
  479. </td>
  480. </tr>
  481. </table>
  482. </body>
  483. </html>