blob: c961dda9cc1c8cb73199eacc25722021aefc959e [file] [log] [blame]
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<title>Java Task</title>
</head>
<body>
<h2><a name="java">Java</a></h2>
<h3>Description</h3>
<p>Executes a Java class within the running (Ant) VM or forks another VM if
specified.</p>
<p>
If odd things go wrong when you run this task, set fork="true" to use a new
JVM.
<h3>Parameters</h3>
<table border="1" cellpadding="2" cellspacing="0">
<tr>
<td valign="top"><b>Attribute</b></td>
<td valign="top"><b>Description</b></td>
<td align="center" valign="top"><b>Required</b></td>
</tr>
<tr>
<td valign="top">classname</td>
<td valign="top">the Java class to execute.</td>
<td align="center" valign="top">Either jar or classname</td>
</tr>
<tr>
<td valign="top">jar</td>
<td valign="top">the location of the jar file to execute (must have a
Main-Class entry in the manifest). Fork must be set to true if this option is selected.</td>
<td align="center" valign="top">Either jar or classname</td>
</tr>
<tr>
<td valign="top">args</td>
<td valign="top">the arguments for the class that is
executed. <b>deprecated, use nested <code>&lt;arg&gt;</code>
elements instead.</b></td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">classpath</td>
<td valign="top">the classpath to use.</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">classpathref</td>
<td valign="top">the classpath to use, given as <a
href="../using.html#references">reference</a> to a PATH defined elsewhere.</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">fork</td>
<td valign="top">if enabled triggers the class execution in another VM
(disabled by default)</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">jvm</td>
<td valign="top">the command used to invoke the Java Virtual Machine,
default is 'java'. The command is resolved by java.lang.Runtime.exec().
Ignored if fork is disabled.
</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">jvmargs</td>
<td valign="top">the arguments to pass to the forked VM (ignored
if fork is disabled). <b>deprecated, use nested
<code>&lt;jvmarg&gt;</code> elements instead.</b></td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">maxmemory</td>
<td valign="top">Max amount of memory to allocate to the forked VM
(ignored if fork is disabled)</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">failonerror</td>
<td valign="top">Stop the buildprocess if the command exits with a
returncode other than 0. Default is "false"</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">dir</td>
<td valign="top">The directory to invoke the VM in. (ignored if
fork is disabled)</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">output</td>
<td valign="top">Name of a file to write the output to.</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">newenvironment</td>
<td valign="top">Do not propagate old environment when new
environment variables are specified. Default is &quot;false&quot;
(ignored if fork is disabled).</td>
<td align="center" valign="top">No</td>
</tr>
</table>
<h3>Parameters specified as nested elements</h3>
<h4>arg and jvmarg</h4>
<p>Use nested <code>&lt;arg&gt;</code> and <code>&lt;jvmarg&gt;</code>
elements to specify arguments for the or the forked VM. See <a
href="../using.html#arg">Command line arguments</a>.</p>
<h4>sysproperty</h4>
<p>Use nested <code>&lt;sysproperty&gt;</code>
elements to specify system properties required by the class.
These properties will be made available to the VM during the execution
of the class (either ANT's VM or the forked VM). The attributes
for this element are the same as for <a href="exec.html#env">environment
variables</a>.</p>
<h4>classpath</h4>
<p><code>Java</code>'s <i>classpath</i> attribute is a <a
href="../using.html#path">PATH like structure</a> and can also be set via a nested
<i>classpath</i> element.</p>
<h4>env</h4>
<p>It is possible to specify environment variables to pass to the
forked VM via nested <i>env</i> elements. See the description in the
section about <a href="exec.html#env">exec</a></p>
<p>Settings will be ignored if fork is disabled.</p>
<h3>Examples</h3>
<pre>
&lt;java classname=&quot;test.Main&quot; &gt;
&lt;arg value=&quot;-h&quot;/&gt;
&lt;classpath&gt;
&lt;pathelement location=&quot;dist/test.jar&quot;/&gt;
&lt;pathelement path=&quot;${java.class.path}&quot;/&gt;
&lt;/classpath&gt;
&lt;/java&gt;
</pre>
Run a class in this JVM with a new jar on the classpath
<pre> &lt;java jar=&quot;dist/test.jar&quot;
fork="true"
failonerror="true"
maxmemory="128m"
&gt;
&lt;arg value=&quot;-h&quot;/&gt;
&lt;classpath&gt;
&lt;pathelement location=&quot;dist/test.jar&quot;/&gt;
&lt;pathelement path=&quot;${java.class.path}&quot;/&gt;
&lt;/classpath&gt;
&lt;/java&gt;
</pre>
Run the jar using the manifest supplied entry point, forking (as required),
and with a maximum memory of 128MB. Any non zero return code breaks the build.
<pre> &lt;java classname=&quot;test.Main&quot;/&gt;</pre>
<pre> &lt;java classname=&quot;test.Main&quot;
fork=&quot;yes&quot; &gt;
&lt;sysproperty key=&quot;DEBUG&quot; value=&quot;true&quot;/&gt;
&lt;arg value=&quot;-h&quot;/&gt;
&lt;jvmarg value=&quot;-Xrunhprof:cpu=samples,file=log.txt,depth=3&quot;/&gt;
&lt;/java&gt;
</pre>
<strong>Note</strong>: you can not specify the (highly deprecated) MSJVM, "jview.exe" as the
JVM, as it takes different parameters for other JVMs,
That JVM can be started from &lt;exec&gt; if required.
<hr>
<p align="center">Copyright &copy; 2001-2002 Apache Software Foundation. All rights
Reserved.</p>
</body>
</html>