## Java

### Description

Executes a Java class within the running (Ant) VM or forks another VM if specified.

Be careful that the executed class doesn't call System.exit(), because it will terminate the VM and thus Ant. In case this happens, it's highly suggested that you set the fork attribute so that System.exit() stops the other VM and not the one that is currently running Ant.

### Parameters

Attribute | Description | Required
classname | the Java class to execute. | Yes
args | the arguments for the class that is executed. deprecated, use nested `<arg>` elements instead. | No
classpath | the classpath to use. | No
classpathref | the classpath to use, given as reference to a PATH defined elsewhere. | No
fork | if enabled triggers the class execution in another VM (disabled by default) | No
jvm | 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. | No
jvmargs | the arguments to pass to the forked VM (ignored if fork is disabled). deprecated, use nested `<jvmarg>` elements instead. | No
maxmemory | Max amount of memory to allocate to the forked VM (ignored if fork is disabled) | No
failonerror | Stop the buildprocess if the command exits with a returncode other than 0. Only available if fork is true. | No
dir | The directory to invoke the VM in. (ignored if fork is disabled) | No
output | Name of a file to write the output to. | No

### Parameters specified as nested elements

#### arg and jvmarg

Use nested `<arg>` and `<jvmarg>` elements to specify arguments for the or the forked VM. See Command line arguments.

#### sysproperty

Use nested `<sysproperty>` 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 environment variables.

#### classpath

`Java`'s classpath attribute is a PATH like structure and can also be set via a nested classpath element.

##### Example

           <java classname="test.Main" >
             <arg value="-h"/>
             <classpath>
               <pathelement location="\test.jar"/>
               <pathelement path="${java.class.path}"/>
             </classpath>
           </java>

### Examples

      <java classname="test.Main"/>

      <java classname="test.Main"
            fork="yes" >
        <sysproperty key="DEBUG" value="true"/>
        <arg value="-h"/>
        <jvmarg value="-Xrunhprof:cpu=samples,file=log.txt,depth=3"/>
      </java>

Copyright © 2000,2001 Apache Software Foundation. All rights Reserved.