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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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">newenvironment</td>
  96. <td valign="top">Do not propagate old environment when new
  97. environment variables are specified. Default is &quot;false&quot;
  98. (ignored if fork is disabled).</td>
  99. <td align="center" valign="top">No</td>
  100. </tr>
  101. </table>
  102. <h3>Parameters specified as nested elements</h3>
  103. <h4>arg and jvmarg</h4>
  104. <p>Use nested <code>&lt;arg&gt;</code> and <code>&lt;jvmarg&gt;</code>
  105. elements to specify arguments for the or the forked VM. See <a
  106. href="../using.html#arg">Command line arguments</a>.</p>
  107. <h4>sysproperty</h4>
  108. <p>Use nested <code>&lt;sysproperty&gt;</code>
  109. elements to specify system properties required by the class.
  110. These properties will be made available to the VM during the execution
  111. of the class (either ANT's VM or the forked VM). The attributes
  112. for this element are the same as for <a href="exec.html#env">environment
  113. variables</a>.</p>
  114. <h4>classpath</h4>
  115. <p><code>Java</code>'s <i>classpath</i> attribute is a <a
  116. href="../using.html#path">PATH like structure</a> and can also be set via a nested
  117. <i>classpath</i> element.</p>
  118. <h4>env</h4>
  119. <p>It is possible to specify environment variables to pass to the
  120. forked VM via nested <i>env</i> elements. See the description in the
  121. section about <a href="exec.html#env">exec</a></p>
  122. <p>Settings will be ignored if fork is disabled.</p>
  123. <h3>Examples</h3>
  124. <pre>
  125. &lt;java classname=&quot;test.Main&quot; &gt;
  126. &lt;arg value=&quot;-h&quot;/&gt;
  127. &lt;classpath&gt;
  128. &lt;pathelement location=&quot;dist/test.jar&quot;/&gt;
  129. &lt;pathelement path=&quot;${java.class.path}&quot;/&gt;
  130. &lt;/classpath&gt;
  131. &lt;/java&gt;
  132. </pre>
  133. Run a class in this JVM with a new jar on the classpath
  134. <pre> &lt;java jar=&quot;dist/test.jar&quot;
  135. fork="true"
  136. failonerror="true"
  137. maxmemory="128m"
  138. &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 the jar using the manifest supplied entry point, forking (as required),
  147. and with a maximum memory of 128MB. Any non zero return code breaks the build.
  148. <pre> &lt;java classname=&quot;test.Main&quot;/&gt;</pre>
  149. <pre> &lt;java classname=&quot;test.Main&quot;
  150. fork=&quot;yes&quot; &gt;
  151. &lt;sysproperty key=&quot;DEBUG&quot; value=&quot;true&quot;/&gt;
  152. &lt;arg value=&quot;-h&quot;/&gt;
  153. &lt;jvmarg value=&quot;-Xrunhprof:cpu=samples,file=log.txt,depth=3&quot;/&gt;
  154. &lt;/java&gt;
  155. </pre>
  156. <strong>Note</strong>: you can not specify the (highly deprecated) MSJVM, "jview.exe" as the
  157. JVM, as it takes different parameters for other JVMs,
  158. That JVM can be started from &lt;exec&gt; if required.
  159. <hr>
  160. <p align="center">Copyright &copy; 2001-2002 Apache Software Foundation. All rights
  161. Reserved.</p>
  162. </body>
  163. </html>