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

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