2001-02-13 12:32:01 +00:00
|
|
|
<html>
|
|
|
|
|
|
|
|
<head>
|
|
|
|
<meta http-equiv="Content-Language" content="en-us">
|
2005-03-07 18:09:10 +00:00
|
|
|
<link rel="stylesheet" type="text/css" href="../stylesheets/style.css"/>
|
2002-02-03 22:00:42 +00:00
|
|
|
<title>Java Task</title>
|
2001-02-13 12:32:01 +00:00
|
|
|
</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>
|
2001-11-20 06:53:06 +00:00
|
|
|
<p>
|
|
|
|
If odd things go wrong when you run this task, set fork="true" to use a new
|
|
|
|
JVM.
|
2003-10-13 13:08:52 +00:00
|
|
|
|
2005-03-16 16:56:03 +00:00
|
|
|
<p>As of Ant 1.6.3, you can interact with a forked VM, as well as
|
2005-01-27 16:36:11 +00:00
|
|
|
sending input to it via the <code>input</code> and <code>inputstring</code>
|
|
|
|
attributes.</p>
|
2003-10-13 13:08:52 +00:00
|
|
|
|
2001-02-13 12:32:01 +00:00
|
|
|
<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>
|
2005-01-10 10:55:23 +00:00
|
|
|
<td align="center" valign="top">Either <tt>jar</tt> or <tt>classname</tt></td>
|
2001-08-02 22:07:47 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">jar</td>
|
2003-12-08 02:27:14 +00:00
|
|
|
<td valign="top">the location of the jar file to execute (must have a
|
2005-01-10 10:55:23 +00:00
|
|
|
Main-Class entry in the manifest). Fork must be set to true if this option is selected.
|
|
|
|
See notes below for more details.
|
|
|
|
</td>
|
|
|
|
<td align="center" valign="top">Either <tt>jar</tt> or <tt>classname</tt></td>
|
2001-02-13 12:32:01 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">args</td>
|
|
|
|
<td valign="top">the arguments for the class that is
|
|
|
|
executed. <b>deprecated, use nested <code><arg></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>
|
2003-07-30 13:56:06 +00:00
|
|
|
<tr>
|
|
|
|
<td valign="top">spawn</td>
|
|
|
|
<td valign="top">if enabled allows to start a process which will outlive ant.<br/>
|
|
|
|
Requires fork=true, and not compatible
|
|
|
|
with timeout, input, output, error, result attributes.<br/>
|
|
|
|
(disabled by default)</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
2001-02-13 12:32:01 +00:00
|
|
|
<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><jvmarg></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
|
2004-04-20 12:48:43 +00:00
|
|
|
returncode other than 0. Default is "false" (see <a href="#failonerror">note</a>)</td>
|
2001-02-13 12:32:01 +00:00
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
2003-04-22 22:12:53 +00:00
|
|
|
<tr>
|
|
|
|
<td valign="top">resultproperty</td>
|
2003-12-08 02:27:14 +00:00
|
|
|
<td valign="top">The name of a property in which the return code of the
|
2003-04-22 22:12:53 +00:00
|
|
|
command should be stored. Only of interest if failonerror=false
|
|
|
|
and if fork=true.</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
2001-02-13 12:32:01 +00:00
|
|
|
<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>
|
2003-12-08 02:27:14 +00:00
|
|
|
<td valign="top">Name of a file to which to write the output. If the error stream
|
2003-02-09 12:17:16 +00:00
|
|
|
is not also redirected to a file or property, it will appear in this output.</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">error</td>
|
|
|
|
<td valign="top">The file to which the standard error of the command should be
|
|
|
|
redirected. </td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">logError</td>
|
|
|
|
<td valign="top">This attribute is used when you wish to see error output in Ant's
|
2003-12-08 02:27:14 +00:00
|
|
|
log and you are redirecting output to a file/property. The error
|
|
|
|
output will not be included in the output file/property. If you
|
2003-02-09 12:17:16 +00:00
|
|
|
redirect error with the "error" or "errorProperty"
|
|
|
|
attributes, this will have no effect.</td>
|
2001-02-13 12:32:01 +00:00
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
2002-04-05 09:28:54 +00:00
|
|
|
<tr>
|
|
|
|
<td valign="top">append</td>
|
2003-02-09 12:17:16 +00:00
|
|
|
<td valign="top">Whether output and error files should be appended to or overwritten.
|
|
|
|
Defaults to false.</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">outputproperty</td>
|
2003-12-08 02:27:14 +00:00
|
|
|
<td valign="top">The name of a property in which the output of the
|
2003-02-09 12:17:16 +00:00
|
|
|
command should be stored. Unless the error stream is redirected to a separate
|
|
|
|
file or stream, this property will include the error output.</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">errorproperty</td>
|
2003-12-08 02:27:14 +00:00
|
|
|
<td valign="top">The name of a property in which the standard error of the
|
2003-02-09 12:17:16 +00:00
|
|
|
command should be stored.</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">input</td>
|
|
|
|
<td valign="top">A file from which the executed command's standard input
|
|
|
|
is taken. This attribute is mutually exclusive with the
|
|
|
|
inputstring attribute</td>
|
2005-01-27 16:36:11 +00:00
|
|
|
<td align="center" valign="top">No; default is to take standard input from console
|
|
|
|
(unless <code>spawn="true"</code>)</td>
|
2003-02-09 12:17:16 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">inputstring</td>
|
2003-12-08 02:27:14 +00:00
|
|
|
<td valign="top">A string which serves as the input stream for the
|
2003-02-09 12:17:16 +00:00
|
|
|
executed command. This attribute is mutually exclusive with the
|
2003-02-09 22:10:57 +00:00
|
|
|
input attribute.</td>
|
2005-01-27 16:36:11 +00:00
|
|
|
<td align="center" valign="top">No; default is to take standard input from console
|
|
|
|
(unless <code>spawn="true"</code>)</td>
|
2002-04-05 09:28:54 +00:00
|
|
|
</tr>
|
2002-01-29 16:20:20 +00:00
|
|
|
<tr>
|
|
|
|
<td valign="top">newenvironment</td>
|
|
|
|
<td valign="top">Do not propagate old environment when new
|
|
|
|
environment variables are specified. Default is "false"
|
|
|
|
(ignored if fork is disabled).</td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
2002-04-08 12:04:07 +00:00
|
|
|
<tr>
|
|
|
|
<td valign="top">timeout</td>
|
|
|
|
<td valign="top">Stop the command if it doesn't finish within the
|
|
|
|
specified time (given in milliseconds). <strong>It is highly
|
|
|
|
recommended to use this feature only if fork is enabled.</strong></td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
2004-04-06 14:09:25 +00:00
|
|
|
<tr>
|
|
|
|
<td valign="top">clonevm</td>
|
|
|
|
<td valign="top">If set to true true, then all system properties
|
|
|
|
and the bootclasspath of the forked Java Virtual Machine will be
|
|
|
|
the same as those of the Java VM running Ant. Default is
|
|
|
|
"false" (ignored if fork is disabled).
|
|
|
|
<em>since Ant 1.7</em></td>
|
|
|
|
<td align="center" valign="top">No</td>
|
|
|
|
</tr>
|
2001-02-13 12:32:01 +00:00
|
|
|
</table>
|
|
|
|
<h3>Parameters specified as nested elements</h3>
|
|
|
|
<h4>arg and jvmarg</h4>
|
|
|
|
<p>Use nested <code><arg></code> and <code><jvmarg></code>
|
2003-12-08 02:27:14 +00:00
|
|
|
elements to specify arguments for the Java class and the forked VM respectively.
|
2002-06-01 12:26:43 +00:00
|
|
|
See <a href="../using.html#arg">Command line arguments</a>.</p>
|
2001-02-13 12:32:01 +00:00
|
|
|
<h4>sysproperty</h4>
|
|
|
|
<p>Use nested <code><sysproperty></code>
|
2003-12-08 02:27:14 +00:00
|
|
|
elements to specify system properties required by the class.
|
2001-02-13 12:32:01 +00:00
|
|
|
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>
|
2003-05-12 15:19:18 +00:00
|
|
|
|
|
|
|
<h4>syspropertyset</h4>
|
|
|
|
|
|
|
|
<p>You can specify a set of properties to be used as system properties
|
|
|
|
with <a href="../CoreTypes/propertyset.html">syspropertyset</a>s.</p>
|
|
|
|
|
|
|
|
<p><em>since Ant 1.6</em>.</p>
|
|
|
|
|
2001-02-13 12:32:01 +00:00
|
|
|
<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>
|
2003-05-27 08:49:42 +00:00
|
|
|
|
|
|
|
<h4>bootclasspath</h4>
|
|
|
|
|
|
|
|
<p>The location of bootstrap class files can be specified using this
|
|
|
|
<a href="../using.html#path">PATH like structure</a> - will be ignored
|
|
|
|
if <i>fork</i> is not <code>true</code> or the target VM doesn't
|
|
|
|
support it (i.e. Java 1.1).</p>
|
|
|
|
|
|
|
|
<p><em>since Ant 1.6</em>.</p>
|
|
|
|
|
2002-01-29 16:20:20 +00:00
|
|
|
<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>
|
2003-08-27 14:23:17 +00:00
|
|
|
|
|
|
|
<h4>permissions</h4>
|
2003-12-08 02:27:14 +00:00
|
|
|
<p>Security permissions can be revoked and granted during the execution of the
|
2003-08-27 14:23:17 +00:00
|
|
|
class via a nested <i>permissions</i> element. For more information please
|
|
|
|
see <a href="../CoreTypes/permissions.html">permissions</a></p>
|
|
|
|
<p>When the permission RuntimePermission exitVM has not been granted (or has
|
2003-12-08 02:27:14 +00:00
|
|
|
been revoked) the System.exit() call will be intercepted
|
2003-08-27 14:23:17 +00:00
|
|
|
and treated like indicated in <i>failonerror</i>.</p>
|
2005-03-14 20:09:54 +00:00
|
|
|
<p>Note:<br/>
|
|
|
|
If you do not specify permissions,
|
|
|
|
a set of default permissions will be added to your Java invocation to make
|
|
|
|
sure that the ant run will continue or terminated as indicated by
|
|
|
|
<i>failonerror</i>. All permissions not granted per default will be
|
|
|
|
checked by whatever security manager was already in place. exitVM will be
|
|
|
|
disallowed.
|
2003-08-28 13:46:33 +00:00
|
|
|
</p>
|
2003-08-27 14:23:17 +00:00
|
|
|
<p>Settings will be ignored if fork is enabled.</p>
|
|
|
|
|
|
|
|
<p><em>since Ant 1.6</em>.</p>
|
2003-12-08 02:27:14 +00:00
|
|
|
|
2004-02-02 14:33:08 +00:00
|
|
|
<h4>assertions</h4>
|
|
|
|
|
|
|
|
<p>You can control enablement of Java 1.4 assertions with an
|
|
|
|
<a href="../CoreTypes/assertions.html"><tt><assertions></tt></a>
|
|
|
|
subelement.</p>
|
|
|
|
|
2004-05-11 11:46:49 +00:00
|
|
|
<p>Assertion statements are currently ignored in non-forked mode.</p>
|
|
|
|
|
2004-02-02 14:33:08 +00:00
|
|
|
<p><em>since Ant 1.6.</em></p>
|
|
|
|
|
2004-03-27 21:22:59 +00:00
|
|
|
<a name="redirector"><h4>redirector</h4></a>
|
|
|
|
<i><b>Since Ant 1.6.2</b></i>
|
|
|
|
<p>A nested <a href="../CoreTypes/redirector.html">I/O Redirector</a>
|
|
|
|
can be specified. In general, the attributes of the redirector behave
|
|
|
|
as the corresponding attributes available at the task level. The most
|
2005-04-20 20:26:00 +00:00
|
|
|
notable peculiarity stems from the retention of the <code><java></code>
|
2004-03-27 21:22:59 +00:00
|
|
|
attributes for backwards compatibility. Any file mapping is done
|
|
|
|
using a <CODE>null</CODE> sourcefile; therefore not all
|
|
|
|
<a href="../CoreTypes/mapper.html">Mapper</a> types will return
|
|
|
|
results. When no results are returned, redirection specifications
|
|
|
|
will fall back to the task level attributes. In practice this means that
|
|
|
|
defaults can be specified for input, output, and error output files.
|
|
|
|
</p>
|
2003-04-22 22:12:53 +00:00
|
|
|
<h3>Errors and return codes</h3>
|
2005-04-20 20:26:00 +00:00
|
|
|
By default the return code of a <code><java></code> is ignored.
|
|
|
|
Alternatively, you can set <code>resultproperty</code> to the name
|
2003-04-22 22:12:53 +00:00
|
|
|
of a property and have it assigned to the result code (barring immutability,
|
|
|
|
of course).
|
2005-04-20 20:26:00 +00:00
|
|
|
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
|
2003-04-22 22:12:53 +00:00
|
|
|
error and would mean the build exits.
|
|
|
|
<p> Similarly, if <code>failonerror="false"</code> and <code>fork="false"</code>
|
2005-04-20 20:26:00 +00:00
|
|
|
, then <code><java></code> <b>must</b> return 0 otherwise the build will
|
|
|
|
exit, as the class was run by the build JVM.</p>
|
2003-04-22 22:12:53 +00:00
|
|
|
|
2005-01-10 10:55:23 +00:00
|
|
|
<h3>JAR file execution</h3>
|
|
|
|
|
|
|
|
The parameter of the <tt>jar</tt> attribute is of type <tt>File</tt>;
|
|
|
|
that is, the parameter is resolved to an absolute file relative to the
|
|
|
|
base directory of the project, <i>not</i> the directory in which the Java
|
|
|
|
task is run. If you need to locate a JAR file relative to the directory
|
|
|
|
the task will be run in, you need to explicitly create the full path
|
|
|
|
to the JAR file.
|
|
|
|
|
|
|
|
|
2001-11-27 20:17:02 +00:00
|
|
|
<h3>Examples</h3>
|
2003-12-08 02:27:14 +00:00
|
|
|
<pre>
|
2002-09-04 11:05:19 +00:00
|
|
|
<java classname="test.Main">
|
2003-12-08 02:27:14 +00:00
|
|
|
<arg value="-h"/>
|
2001-02-13 12:32:01 +00:00
|
|
|
<classpath>
|
2001-11-27 20:17:02 +00:00
|
|
|
<pathelement location="dist/test.jar"/>
|
2001-02-13 12:32:01 +00:00
|
|
|
<pathelement path="${java.class.path}"/>
|
|
|
|
</classpath>
|
|
|
|
</java>
|
|
|
|
</pre>
|
2001-11-27 20:17:02 +00:00
|
|
|
Run a class in this JVM with a new jar on the classpath
|
|
|
|
|
2005-03-10 13:01:55 +00:00
|
|
|
<pre>
|
|
|
|
<java jar="dist/test.jar"
|
2001-11-27 20:17:02 +00:00
|
|
|
fork="true"
|
|
|
|
failonerror="true"
|
|
|
|
maxmemory="128m"
|
|
|
|
>
|
2003-12-08 02:27:14 +00:00
|
|
|
<arg value="-h"/>
|
2001-11-27 20:17:02 +00:00
|
|
|
<classpath>
|
|
|
|
<pathelement location="dist/test.jar"/>
|
|
|
|
<pathelement path="${java.class.path}"/>
|
|
|
|
</classpath>
|
|
|
|
</java>
|
|
|
|
</pre>
|
2005-01-10 10:55:23 +00:00
|
|
|
Run the JAR test.jar in this project's dist/lib directory.
|
|
|
|
using the manifest supplied entry point, forking (as required),
|
2003-12-08 02:27:14 +00:00
|
|
|
and with a maximum memory of 128MB. Any non zero return code breaks the build.
|
2001-11-27 20:17:02 +00:00
|
|
|
|
2005-03-10 13:01:55 +00:00
|
|
|
<pre>
|
|
|
|
<java
|
2005-01-10 10:55:23 +00:00
|
|
|
dir="${exec.dir}"
|
|
|
|
jar="${exec.dir}/dist/test.jar"
|
|
|
|
fork="true"
|
|
|
|
failonerror="true"
|
|
|
|
maxmemory="128m"
|
|
|
|
>
|
|
|
|
<arg value="-h"/>
|
|
|
|
<classpath>
|
|
|
|
<pathelement location="dist/test.jar"/>
|
|
|
|
<pathelement path="${java.class.path}"/>
|
|
|
|
</classpath>
|
|
|
|
</java>
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
Run the JAR dist/test.jar relative to the directory
|
|
|
|
<tt>${exec.dir}</tt>, this being the same directory into which the JVM
|
|
|
|
is to start up.
|
|
|
|
|
|
|
|
|
2001-02-13 12:32:01 +00:00
|
|
|
<pre> <java classname="test.Main"/></pre>
|
2005-03-10 13:01:55 +00:00
|
|
|
<pre>
|
|
|
|
<java classname="test.Main"
|
2001-02-13 12:32:01 +00:00
|
|
|
fork="yes" >
|
2003-12-08 02:27:14 +00:00
|
|
|
<sysproperty key="DEBUG" value="true"/>
|
|
|
|
<arg value="-h"/>
|
|
|
|
<jvmarg value="-Xrunhprof:cpu=samples,file=log.txt,depth=3"/>
|
2001-02-13 12:32:01 +00:00
|
|
|
</java>
|
|
|
|
</pre>
|
2001-11-27 20:17:02 +00:00
|
|
|
<strong>Note</strong>: you can not specify the (highly deprecated) MSJVM, "jview.exe" as the
|
|
|
|
JVM, as it takes different parameters for other JVMs,
|
2004-11-19 09:07:12 +00:00
|
|
|
That JVM can be started from <code><exec></code> if required.
|
2001-02-13 12:32:01 +00:00
|
|
|
<hr>
|
2005-01-10 10:59:31 +00:00
|
|
|
<p align="center">Copyright © 2000-2005 The Apache Software Foundation. All rights
|
2001-02-13 12:32:01 +00:00
|
|
|
Reserved.</p>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|