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.5 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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.
  23. <p>This task runs on Java 1.5 to Java 1.7.</p>
  24. <p>Apt is deprecated in Java 1.6, which can run annotation
  25. processors as part of javac, and removed from the distribution in Java 1.8.
  26. The task will fire an exception when attempting to run under Java 1.8.</p>
  27. <p>This task inherits from the <a href="javac.html">Javac Task</a>, and thus
  28. supports nearly all of the same attributes, and subelements.
  29. There is one special case, the <tt>fork</tt> attribute, which is present
  30. but which can only be set to <tt>true</tt>. That is, apt only works as
  31. a forked process.
  32. </p>
  33. <p>
  34. In addition, it supports
  35. the following addition items:</p>
  36. <h3>Parameters</h3>
  37. <table border="1" cellpadding="2" cellspacing="0">
  38. <tbody><tr>
  39. <td valign="top"><b>Attribute</b></td>
  40. <td valign="top"><b>Description</b></td>
  41. <td align="center" valign="top"><b>Required</b></td>
  42. </tr>
  43. <tr>
  44. <td valign="top">compile</td>
  45. <td valign="top">After running the Apt, should the code be compiled. (see the
  46. <code>-nocompile</code> flag on the Apt executable)</td>
  47. <td align="center" valign="top">No, defaults to false.</td>
  48. </tr>
  49. <tr>
  50. <td valign="top">factory</td>
  51. <td valign="top">The fully qualified classname of the AnnotationProcessFactory to be used
  52. to construct annotation processors. This represents the <code>-factory</code>
  53. command line flag of the Apt executable.</td>
  54. <td align="center" valign="top">No</td>
  55. </tr>
  56. <tr>
  57. <td valign="top">factorypathref</td>
  58. <td valign="top">The reference id of the path used to find the classes needed by the
  59. AnnotationProcessorFactory (and the location of the factory itself).
  60. This represents the <code>-factorypath</code> flag on the Apt executable.</td>
  61. <td align="center" valign="top">No</td>
  62. </tr>
  63. <tr>
  64. <td valign="top">preprocessdir</td>
  65. <td valign="top">The directory used for preprocessing. This is the directory where the
  66. generated source code will be place. This represents the <code>-s</code> flag on
  67. the Apt executable.</td>
  68. <td align="center" valign="top">No</td>
  69. </tr>
  70. </tbody></table>
  71. <h3>Parameters specified as nested elements</h3>
  72. <h4>factorypath</h4>
  73. <p>You can specify the path used to find the classes needed by the AnnotationProcessorFactory
  74. at runtime, using this element. It is represents as a generic path like structure. This
  75. represents the <code>-factorypath</code> flag on the Apt executable.</p>
  76. <h4>option</h4>
  77. <p>Used to represent a generic option to pass to Apt. This represents the <code>-A</code> flag on the
  78. Apt executable. You can specify zero or more <code>&lt;option&gt;</code> elements.</p>
  79. <table border="1" cellpadding="2" cellspacing="0">
  80. <tbody><tr>
  81. <td valign="top" width="12%"><b>Attribute</b></td>
  82. <td valign="top" width="78%"><b>Description</b></td>
  83. <td valign="top" width="10%"><b>Required</b></td>
  84. </tr>
  85. <tr>
  86. <td valign="top">name</td>
  87. <td align="center">The name of the option</td>
  88. <td align="center">Yes.</td>
  89. </tr>
  90. <tr>
  91. <td valign="top">value</td>
  92. <td align="center">The value to set the option to</td>
  93. <td align="center">Yes.</td>
  94. </tr>
  95. </tbody></table>
  96. <h3>Examples</h3>
  97. <blockquote><pre>
  98. &lt;apt srcdir="${src}"
  99. destdir="${build}"
  100. classpath="xyz.jar"
  101. debug="on"
  102. compile="true"
  103. factory="com.mycom.MyAnnotationProcessorFactory"
  104. factorypathref="my.factorypath.id"
  105. preprocessdir="${preprocess.dir}"&gt;
  106. &lt;/apt&gt;
  107. </pre></blockquote>
  108. <p>compiles all <code>.java</code> files under the <code>${src}</code>
  109. directory, and stores
  110. the <code>.class</code> files in the <code>${build}</code> directory.
  111. The classpath used includes <code>xyz.jar</code>, and compiling with
  112. debug information is on. It also forces the generated source code to
  113. be compiled. The generated source code will be placed in
  114. <code>${preprocess.dir}</code> directory, using the class
  115. <code>com.mycom.MyAnnotationProcessorFactory</code> to supply
  116. AnnotationProcessor instances.</p>
  117. <h3>Notes</h3>
  118. <p>
  119. The inherited "fork" attribute is set to true by default; please do not change it.
  120. </p>
  121. <p>
  122. The inherited "compiler" attribute is ignored, as it is forced to use the Apt compiler
  123. </p>
  124. <p>Using the Apt compiler with the "compile" option set to "true"
  125. forces you to use Sun's Apt compiler, which will use the JDK's Javac compiler.
  126. If you wish to use another compiler, you will first need run the Apt processor
  127. with the "compile" flag set to "false", and then use a
  128. <code>&lt;javac&gt;</code> task to compile first your original source code, and then the
  129. generated source code:</p>
  130. <blockquote><pre>
  131. &lt;apt srcdir="${src}"
  132. destdir="${build}"
  133. classpath="xyz.jar"
  134. debug="true"
  135. compile="false"
  136. factory="com.mycom.MyAnnotationProcessorFactory"
  137. factorypathref="my.factorypath.id"
  138. preprocessdir="${preprocess.dir}"&gt;
  139. &lt;/apt&gt;
  140. &lt;javac srcdir="${src}"
  141. destdir="${build}"
  142. classpath="xyz.jar"
  143. debug="on"/&gt;
  144. &lt;javac srcdir="${preprocess.dir}"
  145. destdir="${build}"
  146. classpath="xyz.jar"
  147. debug="true"/&gt;
  148. </pre></blockquote>
  149. This may involve more build file coding, but the speedup gained from switching
  150. to jikes may justify the effort.
  151. <p>
  152. </p>
  153. </body></html>