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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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">jvm</td>
  58. <td valign="top">the command used to invoke the Java Virtual Machine,
  59. default is 'java'. The command is resolved by java.lang.Runtime.exec().
  60. Ignored if fork is disabled.
  61. </td>
  62. <td align="center" valign="top">No</td>
  63. </tr>
  64. <tr>
  65. <td valign="top">jvmargs</td>
  66. <td valign="top">the arguments to pass to the forked VM (ignored
  67. if fork is disabled). <b>deprecated, use nested
  68. <code>&lt;jvmarg&gt;</code> elements instead.</b></td>
  69. <td align="center" valign="top">No</td>
  70. </tr>
  71. <tr>
  72. <td valign="top">maxmemory</td>
  73. <td valign="top">Max amount of memory to allocate to the forked VM
  74. (ignored if fork is disabled)</td>
  75. <td align="center" valign="top">No</td>
  76. </tr>
  77. <tr>
  78. <td valign="top">failonerror</td>
  79. <td valign="top">Stop the buildprocess if the command exits with a
  80. returncode other than 0. Default is "false"</td>
  81. <td align="center" valign="top">No</td>
  82. </tr>
  83. <tr>
  84. <td valign="top">dir</td>
  85. <td valign="top">The directory to invoke the VM in. (ignored if
  86. fork is disabled)</td>
  87. <td align="center" valign="top">No</td>
  88. </tr>
  89. <tr>
  90. <td valign="top">output</td>
  91. <td valign="top">Name of a file to write the output to.</td>
  92. <td align="center" valign="top">No</td>
  93. </tr>
  94. <tr>
  95. <td valign="top">append</td>
  96. <td valign="top">whether output should be appended to or overwrite
  97. an existing file. Defaults to false.</td>
  98. <td align="center" valign="top">No</td>
  99. </tr>
  100. <tr>
  101. <td valign="top">newenvironment</td>
  102. <td valign="top">Do not propagate old environment when new
  103. environment variables are specified. Default is &quot;false&quot;
  104. (ignored if fork is disabled).</td>
  105. <td align="center" valign="top">No</td>
  106. </tr>
  107. <tr>
  108. <td valign="top">timeout</td>
  109. <td valign="top">Stop the command if it doesn't finish within the
  110. specified time (given in milliseconds). <strong>It is highly
  111. recommended to use this feature only if fork is enabled.</strong></td>
  112. <td align="center" valign="top">No</td>
  113. </tr>
  114. </table>
  115. <h3>Parameters specified as nested elements</h3>
  116. <h4>arg and jvmarg</h4>
  117. <p>Use nested <code>&lt;arg&gt;</code> and <code>&lt;jvmarg&gt;</code>
  118. elements to specify arguments for the Java class and the forked VM respectively.
  119. See <a href="../using.html#arg">Command line arguments</a>.</p>
  120. <h4>sysproperty</h4>
  121. <p>Use nested <code>&lt;sysproperty&gt;</code>
  122. elements to specify system properties required by the class.
  123. These properties will be made available to the VM during the execution
  124. of the class (either ANT's VM or the forked VM). The attributes
  125. for this element are the same as for <a href="exec.html#env">environment
  126. variables</a>.</p>
  127. <h4>classpath</h4>
  128. <p><code>Java</code>'s <i>classpath</i> attribute is a <a
  129. href="../using.html#path">PATH like structure</a> and can also be set via a nested
  130. <i>classpath</i> element.</p>
  131. <h4>env</h4>
  132. <p>It is possible to specify environment variables to pass to the
  133. forked VM via nested <i>env</i> elements. See the description in the
  134. section about <a href="exec.html#env">exec</a></p>
  135. <p>Settings will be ignored if fork is disabled.</p>
  136. <h3>Examples</h3>
  137. <pre>
  138. &lt;java classname=&quot;test.Main&quot;&gt;
  139. &lt;arg value=&quot;-h&quot;/&gt;
  140. &lt;classpath&gt;
  141. &lt;pathelement location=&quot;dist/test.jar&quot;/&gt;
  142. &lt;pathelement path=&quot;${java.class.path}&quot;/&gt;
  143. &lt;/classpath&gt;
  144. &lt;/java&gt;
  145. </pre>
  146. Run a class in this JVM with a new jar on the classpath
  147. <pre> &lt;java jar=&quot;dist/test.jar&quot;
  148. fork="true"
  149. failonerror="true"
  150. maxmemory="128m"
  151. &gt;
  152. &lt;arg value=&quot;-h&quot;/&gt;
  153. &lt;classpath&gt;
  154. &lt;pathelement location=&quot;dist/test.jar&quot;/&gt;
  155. &lt;pathelement path=&quot;${java.class.path}&quot;/&gt;
  156. &lt;/classpath&gt;
  157. &lt;/java&gt;
  158. </pre>
  159. Run the jar using the manifest supplied entry point, forking (as required),
  160. and with a maximum memory of 128MB. Any non zero return code breaks the build.
  161. <pre> &lt;java classname=&quot;test.Main&quot;/&gt;</pre>
  162. <pre> &lt;java classname=&quot;test.Main&quot;
  163. fork=&quot;yes&quot; &gt;
  164. &lt;sysproperty key=&quot;DEBUG&quot; value=&quot;true&quot;/&gt;
  165. &lt;arg value=&quot;-h&quot;/&gt;
  166. &lt;jvmarg value=&quot;-Xrunhprof:cpu=samples,file=log.txt,depth=3&quot;/&gt;
  167. &lt;/java&gt;
  168. </pre>
  169. <strong>Note</strong>: you can not specify the (highly deprecated) MSJVM, "jview.exe" as the
  170. JVM, as it takes different parameters for other JVMs,
  171. That JVM can be started from &lt;exec&gt; if required.
  172. <hr>
  173. <p align="center">Copyright &copy; 2000-2002 Apache Software Foundation. All rights
  174. Reserved.</p>
  175. </body>
  176. </html>