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

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