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.

apt.html 6.7 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <!--
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. -->
  15. <html lang="en-us"><head>
  16. <meta http-equiv="Content-Language" content="en-us"><link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
  17. <title>Apt Task</title></head>
  18. <body>
  19. <h2><a name="Apt">Apt</a></h2>
  20. <h3>Description</h3>
  21. <p>Runs the annotation processor tool (apt), and then optionally compiles
  22. the original code, and any generated source code. This task requires Java 1.5.
  23. It may work on later versions, but this cannot be confirmed until those
  24. versions ship. Be advised that the Apt tool does appear to be an unstable
  25. part of the JDK framework, so may change radically in future versions.
  26. In particular it is likely to be obsolete in JDK 6, which can run annotation
  27. processors as part of javac.
  28. If the &lt;apt&gt; task does break when upgrading JVM, please
  29. check to see if there is a more recent version of Ant that tracks
  30. any changes.</p>
  31. <p>This task inherits from the <a href="javac.html">Javac Task</a>, and thus
  32. supports nearly all of the same attributes, and subelements.
  33. There is one special case, the <tt>fork</tt> attribute, which is present
  34. but which can only be set to <tt>true</tt>. That is, apt only works as
  35. a forked process.
  36. </p>
  37. <p>
  38. In addition, it supports
  39. the following addition items:</p>
  40. <h3>Parameters</h3>
  41. <table border="1" cellpadding="2" cellspacing="0">
  42. <tbody><tr>
  43. <td valign="top"><b>Attribute</b></td>
  44. <td valign="top"><b>Description</b></td>
  45. <td align="center" valign="top"><b>Required</b></td>
  46. </tr>
  47. <tr>
  48. <td valign="top">compile</td>
  49. <td valign="top">After running the Apt, should the code be compiled. (see the
  50. <code>-nocompile</code> flag on the Apt executable)</td>
  51. <td align="center" valign="top">No, defaults to false.</td>
  52. </tr>
  53. <tr>
  54. <td valign="top">factory</td>
  55. <td valign="top">The fully qualified classname of the AnnotationProcessFactory to be used
  56. to construct annotation processors. This represents the <code>-factory</code>
  57. command line flag of the Apt executable.</td>
  58. <td align="center" valign="top">No</td>
  59. </tr>
  60. <tr>
  61. <td valign="top">factorypathref</td>
  62. <td valign="top">The reference id of the path used to find the classes needed by the
  63. AnnotationProcessorFactory (and the location of the factory itself).
  64. This represents the <code>-factorypath</code> flag on the Apt executable.</td>
  65. <td align="center" valign="top">No</td>
  66. </tr>
  67. <tr>
  68. <td valign="top">preprocessdir</td>
  69. <td valign="top">The directory used for preprocessing. This is the directory where the
  70. generated source code will be place. This represents the <code>-s</code> flag on
  71. the Apt executable.</td>
  72. <td align="center" valign="top">No</td>
  73. </tr>
  74. </tbody></table>
  75. <h3>Parameters specified as nested elements</h3>
  76. <h4>factorypath</h4>
  77. <p>You can specify the path used to find the classes needed by the AnnotationProcessorFactory
  78. at runtime, using this element. It is represents as a generic path like structure. This
  79. represents the <code>-factorypath</code> flag on the Apt executable.</p>
  80. <h4>option</h4>
  81. <p>Used to represent a generic option to pass to Apt. This represents the <code>-A</code> flag on the
  82. Apt executable. You can specify zero or more <code>&lt;option&gt;</code> elements.</p>
  83. <table border="1" cellpadding="2" cellspacing="0">
  84. <tbody><tr>
  85. <td valign="top" width="12%"><b>Attribute</b></td>
  86. <td valign="top" width="78%"><b>Description</b></td>
  87. <td valign="top" width="10%"><b>Required</b></td>
  88. </tr>
  89. <tr>
  90. <td valign="top">name</td>
  91. <td align="center">The name of the option</td>
  92. <td align="center">Yes.</td>
  93. </tr>
  94. <tr>
  95. <td valign="top">value</td>
  96. <td align="center">The value to set the option to</td>
  97. <td align="center">Yes.</td>
  98. </tr>
  99. </tbody></table>
  100. <h3>Examples</h3>
  101. <blockquote><pre>
  102. &lt;apt srcdir="${src}"
  103. destdir="${build}"
  104. classpath="xyz.jar"
  105. debug="on"
  106. compile="true"
  107. factory="com.mycom.MyAnnotationProcessorFactory"
  108. factorypathref="my.factorypath.id"
  109. preprocessdir="${preprocess.dir}"&gt;
  110. &lt;/apt&gt;
  111. </pre></blockquote>
  112. <p>compiles all <code>.java</code> files under the <code>${src}</code>
  113. directory, and stores
  114. the <code>.class</code> files in the <code>${build}</code> directory.
  115. The classpath used includes <code>xyz.jar</code>, and compiling with
  116. debug information is on. It also forces the generated source code to
  117. be compiled. The generated source code will be placed in
  118. <code>${preprocess.dir}</code> directory, using the class
  119. <code>com.mycom.MyAnnotationProcessorFactory</code> to supply
  120. AnnotationProcessor instances.</p>
  121. <h3>Notes</h3>
  122. <p>
  123. The inherited "fork" attribute is set to true by default; please do not change it.
  124. </p>
  125. <p>
  126. The inherited "compiler" attribute is ignored, as it is forced to use the Apt compiler
  127. </p>
  128. <p>Using the Apt compiler with the "compile" option set to "true"
  129. forces you to use Sun's Apt compiler, which will use the JDK's Javac compiler.
  130. If you wish to use another compiler, you will first need run the Apt processor
  131. with the "compile" flag set to "false", and then use a
  132. <code>&lt;javac&gt;</code> task to compile first your original source code, and then the
  133. generated source code:</p>
  134. <blockquote><pre>
  135. &lt;apt srcdir="${src}"
  136. destdir="${build}"
  137. classpath="xyz.jar"
  138. debug="true"
  139. compile="false"
  140. factory="com.mycom.MyAnnotationProcessorFactory"
  141. factorypathref="my.factorypath.id"
  142. preprocessdir="${preprocess.dir}"&gt;
  143. &lt;/apt&gt;
  144. &lt;javac srcdir="${src}"
  145. destdir="${build}"
  146. classpath="xyz.jar"
  147. debug="on"/&gt;
  148. &lt;javac srcdir="${preprocess.dir}"
  149. destdir="${build}"
  150. classpath="xyz.jar"
  151. debug="true"/&gt;
  152. </pre></blockquote>
  153. This may involve more build file coding, but the speedup gained from switching
  154. to jikes may justify the effort.
  155. <p>
  156. </p>
  157. </body></html>