Apache Ant Java Task

This task is used to execute Java code inside the Ant JVM. We can also use other (outside) JVM by setting fork attribute true.

To get input for the fork JVM, we can use input and inputstring attributes.

Apache Ant Java Task Attributes

AttributeDescriptionRequired
classnameA Java class which is to be executed.Exactly one of the three
jarJar file with location.
moduleMain module name to resolve.
argsThe arguments for the class that is executed.No
classpathThe classpath to use.No
classpathrefThe classpath to use with path reference.No
modulepathIt is used to specify module path.No
modulepathrefThe modulepath with path reference.No
forkIf enabled triggers the class execution in another JVM.No
spawnIt is used to allow to start a process which will outlive Ant.No
jvmIt is a command used to run JVM.No
jvmargsThe JVM arguments, passed to the JVM.No
maxmemoryMax amount of memory to allocate to the forked JVM.No
failonerrorIt stops the build process.No
resultpropertyThe name of a property in which the return code of the command should be stored.No
dirThe directory to be include in run.No
outputOutput file name.No
errorError file name.No
logErrorTo get errors log, store into a file.No
appendWhether output and error files should be appended to or overwritten./td>No
outputpropertyA property in which the output of the command should be stored.No
errorpropertyA property in which the standard error of the command should be stored.No

Apache Ant Java Task Example

This example will run the a Java class Hello.

Run the JAR with maximum memory 128 MB.





Latest Courses