source: release-kits/lirk3/resources/gs3-release-maker/ant/docs/manual/CoreTasks/java.html@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

File size: 12.4 KB
Line 
1<html>
2
3<head>
4<meta http-equiv="Content-Language" content="en-us">
5<title>Java Task</title>
6<link rel="stylesheet" type="text/css" href="../stylesheets/antmanual.css">
7</head>
8
9<body>
10
11<h2><a name="java">Java</a></h2>
12<h3>Description</h3>
13<p>Executes a Java class within the running (Ant) VM or forks another VM if
14specified.</p>
15<p>
16If odd things go wrong when you run this task, set fork="true" to use a new
17JVM.
18
19<p>As of Ant 1.6.3, you can interact with a forked VM, as well as
20sending input to it via the <code>input</code> and <code>inputstring</code>
21attributes.</p>
22
23<h3>Parameters</h3>
24<table border="1" cellpadding="2" cellspacing="0">
25 <tr>
26 <td valign="top"><b>Attribute</b></td>
27 <td valign="top"><b>Description</b></td>
28 <td align="center" valign="top"><b>Required</b></td>
29 </tr>
30 <tr>
31 <td valign="top">classname</td>
32 <td valign="top">the Java class to execute.</td>
33 <td align="center" valign="top">Either jar or classname</td>
34 </tr>
35 <tr>
36 <td valign="top">jar</td>
37 <td valign="top">the location of the jar file to execute (must have a
38 Main-Class entry in the manifest). Fork must be set to true if this option is selected.</td>
39 <td align="center" valign="top">Either jar or classname</td>
40 </tr>
41 <tr>
42 <td valign="top">args</td>
43 <td valign="top">the arguments for the class that is
44 executed. <b>deprecated, use nested <code>&lt;arg&gt;</code>
45 elements instead.</b></td>
46 <td align="center" valign="top">No</td>
47 </tr>
48 <tr>
49 <td valign="top">classpath</td>
50 <td valign="top">the classpath to use.</td>
51 <td align="center" valign="top">No</td>
52 </tr>
53 <tr>
54 <td valign="top">classpathref</td>
55 <td valign="top">the classpath to use, given as <a
56 href="../using.html#references">reference</a> to a PATH defined elsewhere.</td>
57 <td align="center" valign="top">No</td>
58 </tr>
59 <tr>
60 <td valign="top">fork</td>
61 <td valign="top">if enabled triggers the class execution in another VM
62 (disabled by default)</td>
63 <td align="center" valign="top">No</td>
64 </tr>
65 <tr>
66 <td valign="top">spawn</td>
67 <td valign="top">if enabled allows to start a process which will outlive ant.<br/>
68 Requires fork=true, and not compatible
69 with timeout, input, output, error, result attributes.<br/>
70 (disabled by default)</td>
71 <td align="center" valign="top">No</td>
72 </tr>
73 <tr>
74 <td valign="top">jvm</td>
75 <td valign="top">the command used to invoke the Java Virtual Machine,
76 default is 'java'. The command is resolved by java.lang.Runtime.exec().
77 Ignored if fork is disabled.
78 </td>
79 <td align="center" valign="top">No</td>
80 </tr>
81 <tr>
82 <td valign="top">jvmargs</td>
83 <td valign="top">the arguments to pass to the forked VM (ignored
84 if fork is disabled). <b>deprecated, use nested
85 <code>&lt;jvmarg&gt;</code> elements instead.</b></td>
86 <td align="center" valign="top">No</td>
87 </tr>
88 <tr>
89 <td valign="top">maxmemory</td>
90 <td valign="top">Max amount of memory to allocate to the forked VM
91 (ignored if fork is disabled)</td>
92 <td align="center" valign="top">No</td>
93 </tr>
94 <tr>
95 <td valign="top">failonerror</td>
96 <td valign="top">Stop the buildprocess if the command exits with a
97 returncode other than 0. Default is "false" (see <a href="#failonerror">note</a>)</td>
98 <td align="center" valign="top">No</td>
99 </tr>
100 <tr>
101 <td valign="top">resultproperty</td>
102 <td valign="top">The name of a property in which the return code of the
103 command should be stored. Only of interest if failonerror=false
104 and if fork=true.</td>
105 <td align="center" valign="top">No</td>
106 </tr>
107 <tr>
108 <td valign="top">dir</td>
109 <td valign="top">The directory to invoke the VM in. (ignored if
110 fork is disabled)</td>
111 <td align="center" valign="top">No</td>
112 </tr>
113 <tr>
114 <td valign="top">output</td>
115 <td valign="top">Name of a file to which to write the output. If the error stream
116 is not also redirected to a file or property, it will appear in this output.</td>
117 <td align="center" valign="top">No</td>
118 </tr>
119 <tr>
120 <td valign="top">error</td>
121 <td valign="top">The file to which the standard error of the command should be
122 redirected. </td>
123 <td align="center" valign="top">No</td>
124 </tr>
125 <tr>
126 <td valign="top">logError</td>
127 <td valign="top">This attribute is used when you wish to see error output in Ant's
128 log and you are redirecting output to a file/property. The error
129 output will not be included in the output file/property. If you
130 redirect error with the &quot;error&quot; or &quot;errorProperty&quot;
131 attributes, this will have no effect.</td>
132 <td align="center" valign="top">No</td>
133 </tr>
134 <tr>
135 <td valign="top">append</td>
136 <td valign="top">Whether output and error files should be appended to or overwritten.
137 Defaults to false.</td>
138 <td align="center" valign="top">No</td>
139 </tr>
140 <tr>
141 <td valign="top">outputproperty</td>
142 <td valign="top">The name of a property in which the output of the
143 command should be stored. Unless the error stream is redirected to a separate
144 file or stream, this property will include the error output.</td>
145 <td align="center" valign="top">No</td>
146 </tr>
147 <tr>
148 <td valign="top">errorproperty</td>
149 <td valign="top">The name of a property in which the standard error of the
150 command should be stored.</td>
151 <td align="center" valign="top">No</td>
152 </tr>
153 <tr>
154 <td valign="top">input</td>
155 <td valign="top">A file from which the executed command's standard input
156 is taken. This attribute is mutually exclusive with the
157 inputstring attribute</td>
158 <td align="center" valign="top">No; default is to take standard input from console
159 (unless <code>spawn="true"</code>)</td>
160 </tr>
161 <tr>
162 <td valign="top">inputstring</td>
163 <td valign="top">A string which serves as the input stream for the
164 executed command. This attribute is mutually exclusive with the
165 input attribute.</td>
166 <td align="center" valign="top">No; default is to take standard input from console
167 (unless <code>spawn="true"</code>)</td>
168 </tr>
169 <tr>
170 <td valign="top">newenvironment</td>
171 <td valign="top">Do not propagate old environment when new
172 environment variables are specified. Default is &quot;false&quot;
173 (ignored if fork is disabled).</td>
174 <td align="center" valign="top">No</td>
175 </tr>
176 <tr>
177 <td valign="top">timeout</td>
178 <td valign="top">Stop the command if it doesn't finish within the
179 specified time (given in milliseconds). <strong>It is highly
180 recommended to use this feature only if fork is enabled.</strong></td>
181 <td align="center" valign="top">No</td>
182 </tr>
183</table>
184<h3>Parameters specified as nested elements</h3>
185<h4>arg and jvmarg</h4>
186<p>Use nested <code>&lt;arg&gt;</code> and <code>&lt;jvmarg&gt;</code>
187elements to specify arguments for the Java class and the forked VM respectively.
188See <a href="../using.html#arg">Command line arguments</a>.</p>
189<h4>sysproperty</h4>
190<p>Use nested <code>&lt;sysproperty&gt;</code>
191elements to specify system properties required by the class.
192These properties will be made available to the VM during the execution
193of the class (either ANT's VM or the forked VM). The attributes
194for this element are the same as for <a href="exec.html#env">environment
195variables</a>.</p>
196
197<h4>syspropertyset</h4>
198
199<p>You can specify a set of properties to be used as system properties
200with <a href="../CoreTypes/propertyset.html">syspropertyset</a>s.</p>
201
202<p><em>since Ant 1.6</em>.</p>
203
204<h4>classpath</h4>
205<p><code>Java</code>'s <i>classpath</i> attribute is a <a
206href="../using.html#path">PATH like structure</a> and can also be set via a nested
207<i>classpath</i> element.</p>
208
209<h4>bootclasspath</h4>
210
211<p>The location of bootstrap class files can be specified using this
212<a href="../using.html#path">PATH like structure</a> - will be ignored
213if <i>fork</i> is not <code>true</code> or the target VM doesn't
214support it (i.e. Java 1.1).</p>
215
216<p><em>since Ant 1.6</em>.</p>
217
218<h4>env</h4>
219<p>It is possible to specify environment variables to pass to the
220forked VM via nested <i>env</i> elements. See the description in the
221section about <a href="exec.html#env">exec</a></p>
222<p>Settings will be ignored if fork is disabled.</p>
223
224<h4>permissions</h4>
225<p>Security permissions can be revoked and granted during the execution of the
226class via a nested <i>permissions</i> element. For more information please
227see <a href="../CoreTypes/permissions.html">permissions</a></p>
228<p>When the permission RuntimePermission exitVM has not been granted (or has
229been revoked) the System.exit() call will be intercepted
230and treated like indicated in <i>failonerror</i>.</p>
231<p><a name="failonerror">Note:</a>
232if you specify <code>failonerror=&quot;true&quot;</code> and you do not specify permissions,
233a set of default permissions will be added to your Java invocation to make sure that
234a non-zero return code will lead to a <code>BuildException</code>.
235</p>
236<p>Settings will be ignored if fork is enabled.</p>
237
238<p><em>since Ant 1.6</em>.</p>
239
240<h4>assertions</h4>
241
242<p>You can control enablement of Java 1.4 assertions with an
243<a href="../CoreTypes/assertions.html"><tt>&lt;assertions&gt;</tt></a>
244subelement.</p>
245
246<p>Assertion statements are currently ignored in non-forked mode.</p>
247
248<p><em>since Ant 1.6.</em></p>
249
250<a name="redirector"><h4>redirector</h4></a>
251<i><b>Since Ant 1.6.2</b></i>
252<p>A nested <a href="../CoreTypes/redirector.html">I/O Redirector</a>
253can be specified. In general, the attributes of the redirector behave
254as the corresponding attributes available at the task level. The most
255notable peculiarity stems from the retention of the &lt;java&gt;
256attributes for backwards compatibility. Any file mapping is done
257using a <CODE>null</CODE> sourcefile; therefore not all
258<a href="../CoreTypes/mapper.html">Mapper</a> types will return
259results. When no results are returned, redirection specifications
260will fall back to the task level attributes. In practice this means that
261defaults can be specified for input, output, and error output files.
262</p>
263<h3>Errors and return codes</h3>
264By default the return code of a <code>&lt;java&gt;</code> is ignored. Alternatively, you can set <code>resultproperty</code> to the name
265of a property and have it assigned to the result code (barring immutability,
266of course).
267When you set <code>failonerror="true"</code>, the only possible value for <code>resultproperty</code> is 0. Any non zero response is treated as an
268error and would mean the build exits.
269<p> Similarly, if <code>failonerror="false"</code> and <code>fork="false"</code>
270, then <code>&lt;java&gt;</code> <b>must</b> return 0 otherwise the build will exit, as the class was run by the build jvm.</p>
271
272<h3>Examples</h3>
273<pre>
274 &lt;java classname=&quot;test.Main&quot;&gt;
275 &lt;arg value=&quot;-h&quot;/&gt;
276 &lt;classpath&gt;
277 &lt;pathelement location=&quot;dist/test.jar&quot;/&gt;
278 &lt;pathelement path=&quot;${java.class.path}&quot;/&gt;
279 &lt;/classpath&gt;
280 &lt;/java&gt;
281</pre>
282Run a class in this JVM with a new jar on the classpath
283
284<pre>
285 &lt;java jar=&quot;dist/test.jar&quot;
286 fork="true"
287 failonerror="true"
288 maxmemory="128m"
289 &gt;
290 &lt;arg value=&quot;-h&quot;/&gt;
291 &lt;classpath&gt;
292 &lt;pathelement location=&quot;dist/test.jar&quot;/&gt;
293 &lt;pathelement path=&quot;${java.class.path}&quot;/&gt;
294 &lt;/classpath&gt;
295 &lt;/java&gt;
296</pre>
297Run the jar using the manifest supplied entry point, forking (as required),
298and with a maximum memory of 128MB. Any non zero return code breaks the build.
299
300<pre> &lt;java classname=&quot;test.Main&quot;/&gt;</pre>
301<pre>
302 &lt;java classname=&quot;test.Main&quot;
303 fork=&quot;yes&quot; &gt;
304 &lt;sysproperty key=&quot;DEBUG&quot; value=&quot;true&quot;/&gt;
305 &lt;arg value=&quot;-h&quot;/&gt;
306 &lt;jvmarg value=&quot;-Xrunhprof:cpu=samples,file=log.txt,depth=3&quot;/&gt;
307 &lt;/java&gt;
308</pre>
309<strong>Note</strong>: you can not specify the (highly deprecated) MSJVM, "jview.exe" as the
310JVM, as it takes different parameters for other JVMs,
311That JVM can be started from <code>&lt;exec&gt;</code> if required.
312<hr>
313<p align="center">Copyright &copy; 2000-2005 The Apache Software Foundation. All rights
314Reserved.</p>
315
316</body>
317</html>
Note: See TracBrowser for help on using the repository browser.