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

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