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.

java.html 11 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <title>Java Task</title>
  5. </head>
  6. <body>
  7. <h2><a name="java">Java</a></h2>
  8. <h3>Description</h3>
  9. <p>Executes a Java class within the running (Ant) VM or forks another VM if
  10. specified.</p>
  11. <p>
  12. If odd things go wrong when you run this task, set fork="true" to use a new
  13. JVM.
  14. <h3>Parameters</h3>
  15. <table border="1" cellpadding="2" cellspacing="0">
  16. <tr>
  17. <td valign="top"><b>Attribute</b></td>
  18. <td valign="top"><b>Description</b></td>
  19. <td align="center" valign="top"><b>Required</b></td>
  20. </tr>
  21. <tr>
  22. <td valign="top">classname</td>
  23. <td valign="top">the Java class to execute.</td>
  24. <td align="center" valign="top">Either jar or classname</td>
  25. </tr>
  26. <tr>
  27. <td valign="top">jar</td>
  28. <td valign="top">the location of the jar file to execute (must have a
  29. Main-Class entry in the manifest). Fork must be set to true if this option is selected.</td>
  30. <td align="center" valign="top">Either jar or classname</td>
  31. </tr>
  32. <tr>
  33. <td valign="top">args</td>
  34. <td valign="top">the arguments for the class that is
  35. executed. <b>deprecated, use nested <code>&lt;arg&gt;</code>
  36. elements instead.</b></td>
  37. <td align="center" valign="top">No</td>
  38. </tr>
  39. <tr>
  40. <td valign="top">classpath</td>
  41. <td valign="top">the classpath to use.</td>
  42. <td align="center" valign="top">No</td>
  43. </tr>
  44. <tr>
  45. <td valign="top">classpathref</td>
  46. <td valign="top">the classpath to use, given as <a
  47. href="../using.html#references">reference</a> to a PATH defined elsewhere.</td>
  48. <td align="center" valign="top">No</td>
  49. </tr>
  50. <tr>
  51. <td valign="top">fork</td>
  52. <td valign="top">if enabled triggers the class execution in another VM
  53. (disabled by default)</td>
  54. <td align="center" valign="top">No</td>
  55. </tr>
  56. <tr>
  57. <td valign="top">spawn</td>
  58. <td valign="top">if enabled allows to start a process which will outlive ant.<br/>
  59. Requires fork=true, and not compatible
  60. with timeout, input, output, error, result attributes.<br/>
  61. (disabled by default)</td>
  62. <td align="center" valign="top">No</td>
  63. </tr>
  64. <tr>
  65. <td valign="top">jvm</td>
  66. <td valign="top">the command used to invoke the Java Virtual Machine,
  67. default is 'java'. The command is resolved by java.lang.Runtime.exec().
  68. Ignored if fork is disabled.
  69. </td>
  70. <td align="center" valign="top">No</td>
  71. </tr>
  72. <tr>
  73. <td valign="top">jvmargs</td>
  74. <td valign="top">the arguments to pass to the forked VM (ignored
  75. if fork is disabled). <b>deprecated, use nested
  76. <code>&lt;jvmarg&gt;</code> elements instead.</b></td>
  77. <td align="center" valign="top">No</td>
  78. </tr>
  79. <tr>
  80. <td valign="top">maxmemory</td>
  81. <td valign="top">Max amount of memory to allocate to the forked VM
  82. (ignored if fork is disabled)</td>
  83. <td align="center" valign="top">No</td>
  84. </tr>
  85. <tr>
  86. <td valign="top">failonerror</td>
  87. <td valign="top">Stop the buildprocess if the command exits with a
  88. returncode other than 0. Default is "false" (see <a href="#failonerror">note)</a></td>
  89. <td align="center" valign="top">No</td>
  90. </tr>
  91. <tr>
  92. <td valign="top">resultproperty</td>
  93. <td valign="top">The name of a property in which the return code of the
  94. command should be stored. Only of interest if failonerror=false
  95. and if fork=true.</td>
  96. <td align="center" valign="top">No</td>
  97. </tr>
  98. <tr>
  99. <td valign="top">dir</td>
  100. <td valign="top">The directory to invoke the VM in. (ignored if
  101. fork is disabled)</td>
  102. <td align="center" valign="top">No</td>
  103. </tr>
  104. <tr>
  105. <td valign="top">output</td>
  106. <td valign="top">Name of a file to which to write the output. If the error stream
  107. is not also redirected to a file or property, it will appear in this output.</td>
  108. <td align="center" valign="top">No</td>
  109. </tr>
  110. <tr>
  111. <td valign="top">error</td>
  112. <td valign="top">The file to which the standard error of the command should be
  113. redirected. </td>
  114. <td align="center" valign="top">No</td>
  115. </tr>
  116. <tr>
  117. <td valign="top">logError</td>
  118. <td valign="top">This attribute is used when you wish to see error output in Ant's
  119. log and you are redirecting output to a file/property. The error
  120. output will not be included in the output file/property. If you
  121. redirect error with the &quot;error&quot; or &quot;errorProperty&quot;
  122. attributes, this will have no effect.</td>
  123. <td align="center" valign="top">No</td>
  124. </tr>
  125. <tr>
  126. <td valign="top">append</td>
  127. <td valign="top">Whether output and error files should be appended to or overwritten.
  128. Defaults to false.</td>
  129. <td align="center" valign="top">No</td>
  130. </tr>
  131. <tr>
  132. <td valign="top">outputproperty</td>
  133. <td valign="top">The name of a property in which the output of the
  134. command should be stored. Unless the error stream is redirected to a separate
  135. file or stream, this property will include the error output.</td>
  136. <td align="center" valign="top">No</td>
  137. </tr>
  138. <tr>
  139. <td valign="top">errorproperty</td>
  140. <td valign="top">The name of a property in which the standard error of the
  141. command should be stored.</td>
  142. <td align="center" valign="top">No</td>
  143. </tr>
  144. <tr>
  145. <td valign="top">input</td>
  146. <td valign="top">A file from which the executed command's standard input
  147. is taken. This attribute is mutually exclusive with the
  148. inputstring attribute</td>
  149. <td align="center" valign="top">No</td>
  150. </tr>
  151. <tr>
  152. <td valign="top">inputstring</td>
  153. <td valign="top">A string which serves as the input stream for the
  154. executed command. This attribute is mutually exclusive with the
  155. input attribute.</td>
  156. <td align="center" valign="top">No</td>
  157. </tr>
  158. <tr>
  159. <td valign="top">newenvironment</td>
  160. <td valign="top">Do not propagate old environment when new
  161. environment variables are specified. Default is &quot;false&quot;
  162. (ignored if fork is disabled).</td>
  163. <td align="center" valign="top">No</td>
  164. </tr>
  165. <tr>
  166. <td valign="top">timeout</td>
  167. <td valign="top">Stop the command if it doesn't finish within the
  168. specified time (given in milliseconds). <strong>It is highly
  169. recommended to use this feature only if fork is enabled.</strong></td>
  170. <td align="center" valign="top">No</td>
  171. </tr>
  172. </table>
  173. <h3>Parameters specified as nested elements</h3>
  174. <h4>arg and jvmarg</h4>
  175. <p>Use nested <code>&lt;arg&gt;</code> and <code>&lt;jvmarg&gt;</code>
  176. elements to specify arguments for the Java class and the forked VM respectively.
  177. See <a href="../using.html#arg">Command line arguments</a>.</p>
  178. <h4>sysproperty</h4>
  179. <p>Use nested <code>&lt;sysproperty&gt;</code>
  180. elements to specify system properties required by the class.
  181. These properties will be made available to the VM during the execution
  182. of the class (either ANT's VM or the forked VM). The attributes
  183. for this element are the same as for <a href="exec.html#env">environment
  184. variables</a>.</p>
  185. <h4>syspropertyset</h4>
  186. <p>You can specify a set of properties to be used as system properties
  187. with <a href="../CoreTypes/propertyset.html">syspropertyset</a>s.</p>
  188. <p><em>since Ant 1.6</em>.</p>
  189. <h4>classpath</h4>
  190. <p><code>Java</code>'s <i>classpath</i> attribute is a <a
  191. href="../using.html#path">PATH like structure</a> and can also be set via a nested
  192. <i>classpath</i> element.</p>
  193. <h4>bootclasspath</h4>
  194. <p>The location of bootstrap class files can be specified using this
  195. <a href="../using.html#path">PATH like structure</a> - will be ignored
  196. if <i>fork</i> is not <code>true</code> or the target VM doesn't
  197. support it (i.e. Java 1.1).</p>
  198. <p><em>since Ant 1.6</em>.</p>
  199. <h4>env</h4>
  200. <p>It is possible to specify environment variables to pass to the
  201. forked VM via nested <i>env</i> elements. See the description in the
  202. section about <a href="exec.html#env">exec</a></p>
  203. <p>Settings will be ignored if fork is disabled.</p>
  204. <h4>permissions</h4>
  205. <p>Security permissions can be revoked and granted during the execution of the
  206. class via a nested <i>permissions</i> element. For more information please
  207. see <a href="../CoreTypes/permissions.html">permissions</a></p>
  208. <p>When the permission RuntimePermission exitVM has not been granted (or has
  209. been revoked) the System.exit() call will be intercepted
  210. and treated like indicated in <i>failonerror</i>.</p>
  211. <p><a name="failonerror"/>
  212. If you specify <code>failonerror=&quot;true&quot;</code> and you do not specify permissions,
  213. a set of default permissions will be added to your java invocation making sure that
  214. a non zero return code will lead to a <code>BuildException</code>.
  215. </p>
  216. <p>Settings will be ignored if fork is enabled.</p>
  217. <p><em>since Ant 1.6</em>.</p>
  218. <h3>Errors and return codes</h3>
  219. By default the return code of a &lt;java&gt; is ignored. Alternatively, you can set <code>resultproperty</code> to the name
  220. of a property and have it assigned to the result code (barring immutability,
  221. of course).
  222. When you set <code>failonerror="true"</code>, the only possible value for <code>resultproperty</code> is 0. Any non zero response is treated as an
  223. error and would mean the build exits.
  224. <p> Similarly, if <code>failonerror="false"</code> and <code>fork="false"</code>
  225. , then <code>&lt;java&gt;</code> <b>must</b> return 0 otherwise the build will exit, as the class was run by the build jvm.</p>
  226. <h3>Examples</h3>
  227. <pre>
  228. &lt;java classname=&quot;test.Main&quot;&gt;
  229. &lt;arg value=&quot;-h&quot;/&gt;
  230. &lt;classpath&gt;
  231. &lt;pathelement location=&quot;dist/test.jar&quot;/&gt;
  232. &lt;pathelement path=&quot;${java.class.path}&quot;/&gt;
  233. &lt;/classpath&gt;
  234. &lt;/java&gt;
  235. </pre>
  236. Run a class in this JVM with a new jar on the classpath
  237. <pre> &lt;java jar=&quot;dist/test.jar&quot;
  238. fork="true"
  239. failonerror="true"
  240. maxmemory="128m"
  241. &gt;
  242. &lt;arg value=&quot;-h&quot;/&gt;
  243. &lt;classpath&gt;
  244. &lt;pathelement location=&quot;dist/test.jar&quot;/&gt;
  245. &lt;pathelement path=&quot;${java.class.path}&quot;/&gt;
  246. &lt;/classpath&gt;
  247. &lt;/java&gt;
  248. </pre>
  249. Run the jar using the manifest supplied entry point, forking (as required),
  250. and with a maximum memory of 128MB. Any non zero return code breaks the build.
  251. <pre> &lt;java classname=&quot;test.Main&quot;/&gt;</pre>
  252. <pre> &lt;java classname=&quot;test.Main&quot;
  253. fork=&quot;yes&quot; &gt;
  254. &lt;sysproperty key=&quot;DEBUG&quot; value=&quot;true&quot;/&gt;
  255. &lt;arg value=&quot;-h&quot;/&gt;
  256. &lt;jvmarg value=&quot;-Xrunhprof:cpu=samples,file=log.txt,depth=3&quot;/&gt;
  257. &lt;/java&gt;
  258. </pre>
  259. <strong>Note</strong>: you can not specify the (highly deprecated) MSJVM, "jview.exe" as the
  260. JVM, as it takes different parameters for other JVMs,
  261. That JVM can be started from &lt;exec&gt; if required.
  262. <hr>
  263. <p align="center">Copyright &copy; 2000-2003 Apache Software Foundation. All rights
  264. Reserved.</p>
  265. </body>
  266. </html>