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 5.9 KiB

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