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.

librarys.html 19 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <!-- Content Stylesheet for Site -->
  3. <!-- start the processing -->
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
  7. <meta name="author" value="Peter Donald">
  8. <meta name="email" value="peter@apache.org">
  9. <title>Apache Myrmidon - On Libraries in Ant 2</title>
  10. </head>
  11. <body bgcolor="#ffffff" text="#000000" link="#525D76">
  12. <table border="0" width="100%" cellspacing="0">
  13. <!-- TOP IMAGE -->
  14. <tr>
  15. <td> <td colspan="2">
  16. <a href="http://jakarta.apache.org"><img src="http://jakarta.apache.org/images/jakarta-logo.gif" align="left" border="0"/></a>
  17. </td>
  18. </td>
  19. <td valign="bottom"><div align="right"><b><font size="+3" color="#525D76">Apache Myrmidon</font></b></div></td>
  20. </tr>
  21. </table>
  22. <table border="0" width="100%" cellspacing="4">
  23. <tr><td colspan="2">
  24. <hr noshade="" size="1"/>
  25. </td></tr>
  26. <tr>
  27. <!-- LEFT SIDE NAVIGATION -->
  28. <td valign="top" nowrap="true">
  29. <p><strong>Myrmidon</strong></p>
  30. <ul>
  31. <li> <a href="./index.html">Introduction</a>
  32. </li>
  33. <li> <a href="./getinvolved.html">Get Involved</a>
  34. </li>
  35. <li> <a href="./user.html">Building Myrmidon</a>
  36. </li>
  37. <li> <a href="./todo.html">Todo List</a>
  38. </li>
  39. </ul>
  40. <p><strong>User Guide</strong></p>
  41. <ul>
  42. <li> <a href="./buildfile.html">Project File</a>
  43. </li>
  44. <li> <a href="./vfs.html">Virtual File System</a>
  45. </li>
  46. <li> <a href="./ant1compat.html">Ant 1 Compatibility Layer</a>
  47. </li>
  48. <li> <a href="./differences.html">Differences to Ant 1</a>
  49. </li>
  50. <li> <a href="./task.html">My First Task</a>
  51. </li>
  52. </ul>
  53. <p><strong>Extending Ant</strong></p>
  54. <ul>
  55. <li> <a href="./configuring.html">Configuration HOWTO</a>
  56. </li>
  57. <li> <a href="./converter.html">Converter HOWTO</a>
  58. </li>
  59. <li> <a href="./type.html">Type HOWTO</a>
  60. </li>
  61. <li> <a href="./classloader.html">ClassLoader HOWTO</a>
  62. </li>
  63. <li> <a href="./librarys.html">Library HOWTO</a>
  64. </li>
  65. </ul>
  66. <p><strong>Container Design</strong></p>
  67. <ul>
  68. </ul>
  69. </td>
  70. <td align="left" valign="top">
  71. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  72. <tr><td bgcolor="#525D76">
  73. <font color="#ffffff" face="arial,helvetica,sanserif">
  74. <a name="Library Management"><strong>Library Management</strong></a>
  75. </font>
  76. </td></tr>
  77. <tr><td>
  78. <blockquote>
  79. <p>Long ago there was identified the need for libraries that contain
  80. tasks and other elements present in the build file. This document
  81. attempts to describe the mechanism via which these libraries will be
  82. defined and used in Ant 2. The libraries (also referred to as
  83. deployments) will be termed antlibs.</p>
  84. <p>Ant libraries can be packaged and signed into a ANt Type Library
  85. format (.atl) using the standard Java Archive tools. (For details on
  86. the .jar file format see the
  87. <a href="http://java.sun.com/j2se/1.3/docs/guide/jar/index.html">
  88. Jar Specification</a>.
  89. </p>
  90. <p>When packaged into such a form the META-INF/ directory contains
  91. ant specific descriptors in addition to the standard Jar manifest
  92. and other descriptor files. The archive will also contain the
  93. <code>.class</code> files for all the tasks and other types the
  94. library defines. It may also contain additional resources that can
  95. be referenced in the build file (an example being DTDs).
  96. </p>
  97. <p>The library may also need access to other libraries or resources
  98. to perform its job. For instance, if the task loaded an XML document
  99. and then processed said document using the
  100. <em>Trax API</em> then
  101. the Ant library needs to have access to the
  102. <em>Trax API</em> and an
  103. implementation of the API. The Antlib mechanism thus uses the standard
  104. "Optional Package" Specification to declare dependencies on other
  105. libraries.
  106. </p>
  107. <p>The libraries will usually be installed in standard locations that
  108. make it possible for the Ant container to automatically locate and scan
  109. the libraries. It will also be possible for the users to specify
  110. additional search locations or even the specific location of ant
  111. libraries.</p>
  112. <p>The following sections will describe each of these different facets
  113. in greater detail.</p>
  114. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  115. <tr><td bgcolor="#828DA6">
  116. <font color="#ffffff" face="arial,helvetica,sanserif">
  117. <a name="Descriptors"><strong>Descriptors</strong></a>
  118. </font>
  119. </td></tr>
  120. <tr><td>
  121. <blockquote>
  122. <p>FIXME: Import this part from other doco</p>
  123. </blockquote>
  124. </td></tr>
  125. </table>
  126. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  127. <tr><td bgcolor="#828DA6">
  128. <font color="#ffffff" face="arial,helvetica,sanserif">
  129. <a name="Class and Resource Files"><strong>Class and Resource Files</strong></a>
  130. </font>
  131. </td></tr>
  132. <tr><td>
  133. <blockquote>
  134. <p>The class and resources files should be stored as in standard jars. The
  135. root directory being the base via which code and resources are loaded. So
  136. the
  137. <code>.class</code> file for the Java class
  138. <code>com.biz.tasks.Mytask</code>
  139. would be stored in
  140. <code>/com/biz/tasks/Mytask.class</code>
  141. </p>
  142. </blockquote>
  143. </td></tr>
  144. </table>
  145. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  146. <tr><td bgcolor="#828DA6">
  147. <font color="#ffffff" face="arial,helvetica,sanserif">
  148. <a name="Dependencies"><strong>Dependencies</strong></a>
  149. </font>
  150. </td></tr>
  151. <tr><td>
  152. <blockquote>
  153. <p>It is often the case that a library will need external resources. The
  154. example given above described dependence on an external XML library. The
  155. ant library thus needs a mechanism via which to declare dependencies on
  156. external libraries.</p>
  157. <p>Ant 2 uses the "Optional Package" mechanism. Prior to JDK1.3, an "Optional
  158. Package" was known as an
  159. <em>Extension</em>. The specification for this
  160. mechanism is available in the JDK1.3 documentation in the directory
  161. <code>$JDK_HOME/docs/guide/extensions/versioning.html</code>. Alternatively
  162. it is available online at
  163. <a href="http://java.sun.com/j2se/1.3/docs/guide/extensions/versioning.html">
  164. http://java.sun.com/j2se/1.3/docs/guide/extensions/versioning.html</a>.
  165. </p>
  166. <p>This mechanism was adopted as it is an established standard. The standard
  167. is also begining to be adopted by other specifications such as the
  168. <em>Servlet
  169. 2.3 API</em>. Thus we are likely to see an increase of jars using this mechanism
  170. to specify dependencies.
  171. </p>
  172. <p>The "Optional Package" mechanism allows jars to specify dependencies on other
  173. jars that implement a particular specification at particular version levels. For
  174. example you could specify a dependency on the Trax 1.1 API by adding the following
  175. to the manifest of your jar.</p>
  176. <div align="left">
  177. <table cellspacing="4" cellpadding="0" border="0">
  178. <tr>
  179. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  180. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  181. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  182. </tr>
  183. <tr>
  184. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  185. <td bgcolor="#ffffff"><pre>
  186. Extension-List: trax
  187. trax-Extension-Name: Java API for XML Parsing
  188. trax-Specification-Version: 1.1
  189. </pre></td>
  190. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  191. </tr>
  192. <tr>
  193. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  194. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  195. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  196. </tr>
  197. </table>
  198. </div>
  199. <p>In some cases you may also wish to specify a dependency on a specific vendors
  200. implementation. For instance you may need to use xalan due to it implementing a
  201. particular extension you need. In that case you manifest may contain;</p>
  202. <div align="left">
  203. <table cellspacing="4" cellpadding="0" border="0">
  204. <tr>
  205. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  206. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  207. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  208. </tr>
  209. <tr>
  210. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  211. <td bgcolor="#ffffff"><pre>
  212. Extension-List: trax
  213. trax-Extension-Name: Java API for XML Parsing
  214. trax-Specification-Version: 1.1
  215. trax-Implementation-Title: org.apache.xalan.xslt
  216. trax-Implementation-Version: 2.1.0
  217. trax-Implementation-Vendor: Apache Software Foundation
  218. </pre></td>
  219. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  220. </tr>
  221. <tr>
  222. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  223. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  224. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  225. </tr>
  226. </table>
  227. </div>
  228. <p>In many cases there will be no distinction between the specification and
  229. the implementation of a library. For instance the Velocity project only has
  230. one implementation and one specification. In which case it is sufficient to
  231. just declare a dependency on the Velocity "Specification". A library that uses
  232. both the Trax API and the Velocity project may look like;</p>
  233. <div align="left">
  234. <table cellspacing="4" cellpadding="0" border="0">
  235. <tr>
  236. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  237. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  238. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  239. </tr>
  240. <tr>
  241. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  242. <td bgcolor="#ffffff"><pre>
  243. Extension-List: trax velocity
  244. velocity-Extension-Name: org.apache.velocity
  245. velocity-Specification-Version: 1.0
  246. trax-Extension-Name: Java API for XML Parsing
  247. trax-Specification-Version: 1.1
  248. trax-Implementation-Title: org.apache.xalan.xslt
  249. trax-Implementation-Version: 2.1.0
  250. trax-Implementation-Vendor: Apache Software Foundation
  251. </pre></td>
  252. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  253. </tr>
  254. <tr>
  255. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  256. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  257. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  258. </tr>
  259. </table>
  260. </div>
  261. <p>To make other jars available to Ant libraries as "Optional Packages"
  262. or Extensions then you need to add a few lines to the manifest of the
  263. other jar. The minimal manifest is the following;</p>
  264. <div align="left">
  265. <table cellspacing="4" cellpadding="0" border="0">
  266. <tr>
  267. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  268. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  269. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  270. </tr>
  271. <tr>
  272. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  273. <td bgcolor="#ffffff"><pre>
  274. Extension-Name: org.realityforge.dve
  275. Specification-Vendor: Peter Donald
  276. Specification-Version: 1.0
  277. </pre></td>
  278. <td bgcolor="#023264" width="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  279. </tr>
  280. <tr>
  281. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  282. <td bgcolor="#023264" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  283. <td bgcolor="#023264" width="1" height="1"><img src="/images/void.gif" width="1" height="1" vspace="0" hspace="0" border="0"/></td>
  284. </tr>
  285. </table>
  286. </div>
  287. <p>It is important to note that looking for dependencies is recursive. For example,
  288. if the ant library depends upon jar A and and A depends on B then both A and B will
  289. need to be loaded by the container.</p>
  290. </blockquote>
  291. </td></tr>
  292. </table>
  293. <table border="0" cellspacing="0" cellpadding="2" width="100%">
  294. <tr><td bgcolor="#828DA6">
  295. <font color="#ffffff" face="arial,helvetica,sanserif">
  296. <a name="Implementation Notes"><strong>Implementation Notes</strong></a>
  297. </font>
  298. </td></tr>
  299. <tr><td>
  300. <blockquote>
  301. <p>So far there has been no mention of implementation strategies for
  302. managing ClassLoaders and other details about where the "Optional Packages"
  303. are stored. This section will outline such details but they could change
  304. in the future. The above specification will still be accurate but the approach
  305. to implementing specification will be different.</p>
  306. <p>In the current architecture all of the "Optional Packages" are assumed to
  307. be stored in the
  308. <code>$ANT_HOME/ext</code> directory. The runtime will scan
  309. this directory for jars and add all the "optional Packages" found into a
  310. registry. This registry will be used by the library loading mechanism to locate
  311. all the "Optional Packages". The user is able to specify an alternative directory
  312. or add a new directory to search on the commandline.
  313. </p>
  314. <p>When the container attempts to load an ant library it will also try to load
  315. any needed dependencies. First it will check the parent ClassLoaders to see if any
  316. of them contain the required dependencies. If not then it will search the
  317. "Optional Packages" registry. If the dependency is not found then a error will be
  318. signaled. If the dependency is found in the "Optional Packages" registry then it is
  319. loaded by the same ClassLoader that is used to load the Ant library.</p>
  320. </blockquote>
  321. </td></tr>
  322. </table>
  323. </blockquote>
  324. </td></tr>
  325. </table>
  326. </td>
  327. </tr>
  328. <!-- FOOTER -->
  329. <tr><td colspan="2">
  330. <hr noshade="" size="1"/>
  331. </td></tr>
  332. <tr><td colspan="2">
  333. <div align="center"><font color="#525D76" size="-1"><em>
  334. Copyright &#169; 2000-2002, Apache Software Foundation
  335. </em></font></div>
  336. </td></tr>
  337. </table>
  338. </body>
  339. </html>
  340. <!-- end the processing -->