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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <title>Apache Ant User Manual</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. </table>
  95. <h3>Parameters specified as nested elements</h3>
  96. <h4>arg and jvmarg</h4>
  97. <p>Use nested <code>&lt;arg&gt;</code> and <code>&lt;jvmarg&gt;</code>
  98. elements to specify arguments for the or the forked VM. See <a
  99. href="../using.html#arg">Command line arguments</a>.</p>
  100. <h4>sysproperty</h4>
  101. <p>Use nested <code>&lt;sysproperty&gt;</code>
  102. elements to specify system properties required by the class.
  103. These properties will be made available to the VM during the execution
  104. of the class (either ANT's VM or the forked VM). The attributes
  105. for this element are the same as for <a href="exec.html#env">environment
  106. variables</a>.</p>
  107. <h4>classpath</h4>
  108. <p><code>Java</code>'s <i>classpath</i> attribute is a <a
  109. href="../using.html#path">PATH like structure</a> and can also be set via a nested
  110. <i>classpath</i> element.</p>
  111. <h3>Examples</h3>
  112. <pre>
  113. &lt;java classname=&quot;test.Main&quot; &gt;
  114. &lt;arg value=&quot;-h&quot;/&gt;
  115. &lt;classpath&gt;
  116. &lt;pathelement location=&quot;dist/test.jar&quot;/&gt;
  117. &lt;pathelement path=&quot;${java.class.path}&quot;/&gt;
  118. &lt;/classpath&gt;
  119. &lt;/java&gt;
  120. </pre>
  121. Run a class in this JVM with a new jar on the classpath
  122. <pre> &lt;java jar=&quot;dist/test.jar&quot;
  123. fork="true"
  124. failonerror="true"
  125. maxmemory="128m"
  126. &gt;
  127. &lt;arg value=&quot;-h&quot;/&gt;
  128. &lt;classpath&gt;
  129. &lt;pathelement location=&quot;dist/test.jar&quot;/&gt;
  130. &lt;pathelement path=&quot;${java.class.path}&quot;/&gt;
  131. &lt;/classpath&gt;
  132. &lt;/java&gt;
  133. </pre>
  134. Run the jar using the manifest supplied entry point, forking (as required),
  135. and with a maximum memory of 128MB. Any non zero return code breaks the build.
  136. <pre> &lt;java classname=&quot;test.Main&quot;/&gt;</pre>
  137. <pre> &lt;java classname=&quot;test.Main&quot;
  138. fork=&quot;yes&quot; &gt;
  139. &lt;sysproperty key=&quot;DEBUG&quot; value=&quot;true&quot;/&gt;
  140. &lt;arg value=&quot;-h&quot;/&gt;
  141. &lt;jvmarg value=&quot;-Xrunhprof:cpu=samples,file=log.txt,depth=3&quot;/&gt;
  142. &lt;/java&gt;
  143. </pre>
  144. <strong>Note</strong>: you can not specify the (highly deprecated) MSJVM, "jview.exe" as the
  145. JVM, as it takes different parameters for other JVMs,
  146. That JVM can be started from &lt;exec&gt; if required.
  147. <hr>
  148. <p align="center">Copyright &copy; 2000,2001 Apache Software Foundation. All rights
  149. Reserved.</p>
  150. </body>
  151. </html>