org.apache.tools.ant.taskdefs

Class Java

public class Java extends Task

Launcher for Java applications. Allows use of the same JVM for the called application thus resulting in much faster operation.

Since: Ant 1.1

UNKNOWN: category="java"

Field Summary
protected Redirectorredirector
protected RedirectorElementredirectorElement
Constructor Summary
Java()
Normal constructor
Java(Task owner)
create a bound task
Method Summary
voidaddAssertions(Assertions asserts)
Add assertions to enable in this program (if fork=true).
voidaddConfiguredRedirector(RedirectorElement redirectorElement)
Add a RedirectorElement to this task.
voidaddEnv(Environment.Variable var)
Add an environment variable.
voidaddSysproperty(Environment.Variable sysp)
Add a system property.
voidaddSyspropertyset(PropertySet sysp)
Add a set of properties as system properties.
voidclearArgs()
Clear out the arguments to this java task.
Commandline.ArgumentcreateArg()
Add a command-line argument.
PathcreateBootclasspath()
Add a path to the bootclasspath.
PathcreateClasspath()
Add a path to the classpath.
Commandline.ArgumentcreateJvmarg()
Adds a JVM argument.
PermissionscreatePermissions()
Set the permissions for the application run inside the same JVM.
protected ExecuteWatchdogcreateWatchdog()
Create the Watchdog to kill a runaway process.
voidexecute()
Do the execution.
intexecuteJava()
Do the execution and return a return code.
CommandlineJavagetCommandLine()
Accessor to the command line.
CommandlineJava.SysPropertiesgetSysProperties()
Get the system properties of the command line.
protected voidhandleErrorFlush(String output)
Handle output sent to System.err and flush the stream.
protected voidhandleErrorOutput(String output)
Handle output sent to System.err.
protected voidhandleFlush(String output)
Pass output sent to System.out to specified output file.
inthandleInput(byte[] buffer, int offset, int length)
Handle an input request by this task.
protected voidhandleOutput(String output)
Pass output sent to System.out to specified output file.
protected voidmaybeSetResultPropertyValue(int result)
Helper method to set result property to the passed in value if appropriate.
protected voidrun(String classname, Vector args)
Executes the given classname with the given arguments as if it were a command line application.
voidsetAppend(boolean append)
If true, append output to existing file.
voidsetArgs(String s)
Deprecated: use nested arg instead.
voidsetClassname(String s)
Set the Java class to execute.
voidsetClasspath(Path s)
Set the classpath to be used when running the Java class.
voidsetClasspathRef(Reference r)
Set the classpath to use by reference.
voidsetCloneVm(boolean cloneVm)
If set, system properties will be copied to the cloned VM--as well as the bootclasspath unless you have explicitly specified a bootclaspath.
voidsetDir(File d)
Set the working directory of the process.
voidsetError(File error)
Set the File to which the error stream of the process is redirected.
voidsetErrorProperty(String errorProperty)
Set the property name whose value should be set to the error of the process.
voidsetFailonerror(boolean fail)
If true, then fail if the command exits with a returncode other than zero.
voidsetFork(boolean s)
If true, execute in a new VM.
voidsetInput(File input)
Set the input to use for the task.
voidsetInputString(String inputString)
Set the string to use as input.
voidsetJar(File jarfile)
Set the location of the JAR file to execute.
voidsetJvm(String s)
Set the command used to start the VM (only if forking).
voidsetJvmargs(String s)
Set the command line arguments for the JVM.
voidsetJVMVersion(String value)
Set the JVM version.
voidsetLogError(boolean logError)
Set whether error output of exec is logged.
voidsetMaxmemory(String max)
Corresponds to -mx or -Xmx depending on VM version.
voidsetNewenvironment(boolean newenv)
If true, use a completely new environment.
voidsetOutput(File out)
Set the File to which the output of the process is redirected.
voidsetOutputproperty(String outputProp)
Set the property name whose value should be set to the output of the process.
voidsetResultProperty(String resultProperty)
Set the name of the property in which the return code of the command should be stored.
voidsetSpawn(boolean spawn)
Set whether or not you want the process to be spawned; default is not spawned.
voidsetTimeout(Long value)
Set the timeout in milliseconds after which the process will be killed.
protected voidsetupRedirector()
Set up properties on the redirector that we needed to store locally.

Field Detail

redirector

protected Redirector redirector

redirectorElement

protected RedirectorElement redirectorElement

Constructor Detail

Java

public Java()
Normal constructor

Java

public Java(Task owner)
create a bound task

Parameters: owner owner

Method Detail

addAssertions

public void addAssertions(Assertions asserts)
Add assertions to enable in this program (if fork=true).

Parameters: asserts assertion set.

Since: Ant 1.6

addConfiguredRedirector

public void addConfiguredRedirector(RedirectorElement redirectorElement)
Add a RedirectorElement to this task.

Parameters: redirectorElement RedirectorElement.

addEnv

public void addEnv(Environment.Variable var)
Add an environment variable.

Will be ignored if we are not forking a new VM.

Parameters: var new environment variable.

Since: Ant 1.5

addSysproperty

public void addSysproperty(Environment.Variable sysp)
Add a system property.

Parameters: sysp system property.

addSyspropertyset

public void addSyspropertyset(PropertySet sysp)
Add a set of properties as system properties.

Parameters: sysp set of properties to add.

Since: Ant 1.6

clearArgs

public void clearArgs()
Clear out the arguments to this java task.

createArg

public Commandline.Argument createArg()
Add a command-line argument.

Returns: created argument.

createBootclasspath

public Path createBootclasspath()
Add a path to the bootclasspath.

Returns: created bootclasspath.

Since: Ant 1.6

createClasspath

public Path createClasspath()
Add a path to the classpath.

Returns: created classpath.

createJvmarg

public Commandline.Argument createJvmarg()
Adds a JVM argument.

Returns: JVM argument created.

createPermissions

public Permissions createPermissions()
Set the permissions for the application run inside the same JVM.

Returns: Permissions.

Since: Ant 1.6

createWatchdog

protected ExecuteWatchdog createWatchdog()
Create the Watchdog to kill a runaway process.

Returns: new watchdog.

Throws: BuildException under unknown circumstances.

Since: Ant 1.5

execute

public void execute()
Do the execution.

Throws: BuildException if failOnError is set to true and the application returns a nonzero result code.

executeJava

public int executeJava()
Do the execution and return a return code.

Returns: the return code from the execute java class if it was executed in a separate VM (fork = "yes") or a security manager was installed that prohibits ExitVM (default).

Throws: BuildException if required parameters are missing.

getCommandLine

public CommandlineJava getCommandLine()
Accessor to the command line.

Returns: the current command line.

Since: 1.6.3

getSysProperties

public CommandlineJava.SysProperties getSysProperties()
Get the system properties of the command line.

Returns: the current properties of this java invocation.

Since: 1.6.3

handleErrorFlush

protected void handleErrorFlush(String output)
Handle output sent to System.err and flush the stream.

Parameters: output string of stderr.

Since: Ant 1.5.2

handleErrorOutput

protected void handleErrorOutput(String output)
Handle output sent to System.err.

Parameters: output string of stderr.

Since: Ant 1.5

handleFlush

protected void handleFlush(String output)
Pass output sent to System.out to specified output file.

Parameters: output string of output on its way to its handlers.

Since: Ant 1.5.2

handleInput

public int handleInput(byte[] buffer, int offset, int length)
Handle an input request by this task.

Parameters: buffer the buffer into which data is to be read. offset the offset into the buffer at which data is stored. length the amount of data to read.

Returns: the number of bytes read.

Throws: IOException if the data cannot be read.

Since: Ant 1.6

handleOutput

protected void handleOutput(String output)
Pass output sent to System.out to specified output file.

Parameters: output a string of output on its way to the handlers.

Since: Ant 1.5

maybeSetResultPropertyValue

protected void maybeSetResultPropertyValue(int result)
Helper method to set result property to the passed in value if appropriate.

Parameters: result the exit code

run

protected void run(String classname, Vector args)
Executes the given classname with the given arguments as if it were a command line application.

Parameters: classname the name of the class to run. args arguments for the class.

Throws: BuildException in case of IOException in the execution.

setAppend

public void setAppend(boolean append)
If true, append output to existing file.

Parameters: append if true, append output to existing file.

Since: Ant 1.5

setArgs

public void setArgs(String s)
Deprecated: use nested arg instead. Set the command line arguments for the class.

Parameters: s arguments.

UNKNOWN: ignore="true"

setClassname

public void setClassname(String s)
Set the Java class to execute.

Parameters: s the name of the main class.

Throws: BuildException if the jar attribute has been set.

setClasspath

public void setClasspath(Path s)
Set the classpath to be used when running the Java class.

Parameters: s an Ant Path object containing the classpath.

setClasspathRef

public void setClasspathRef(Reference r)
Set the classpath to use by reference.

Parameters: r a reference to an existing classpath.

setCloneVm

public void setCloneVm(boolean cloneVm)
If set, system properties will be copied to the cloned VM--as well as the bootclasspath unless you have explicitly specified a bootclaspath.

Doesn't have any effect unless fork is true.

Parameters: cloneVm if true copy system properties.

Since: Ant 1.7

setDir

public void setDir(File d)
Set the working directory of the process.

Parameters: d working directory.

setError

public void setError(File error)
Set the File to which the error stream of the process is redirected.

Parameters: error file getting the error stream.

Since: Ant 1.6

setErrorProperty

public void setErrorProperty(String errorProperty)
Set the property name whose value should be set to the error of the process.

Parameters: errorProperty property name.

Since: Ant 1.6

setFailonerror

public void setFailonerror(boolean fail)
If true, then fail if the command exits with a returncode other than zero.

Parameters: fail if true fail the build when the command exits with a nonzero returncode.

setFork

public void setFork(boolean s)
If true, execute in a new VM.

Parameters: s do you want to run Java in a new VM.

setInput

public void setInput(File input)
Set the input to use for the task.

Parameters: input name of the input file.

setInputString

public void setInputString(String inputString)
Set the string to use as input.

Parameters: inputString the string which is used as the input source.

setJar

public void setJar(File jarfile)
Set the location of the JAR file to execute.

Parameters: jarfile the jarfile to execute.

Throws: BuildException if there is also a main class specified.

setJvm

public void setJvm(String s)
Set the command used to start the VM (only if forking).

Parameters: s command to start the VM.

setJvmargs

public void setJvmargs(String s)
Set the command line arguments for the JVM.

Parameters: s jvmargs.

setJVMVersion

public void setJVMVersion(String value)
Set the JVM version.

Parameters: value JVM version.

setLogError

public void setLogError(boolean logError)
Set whether error output of exec is logged. This is only useful when output is being redirected and error output is desired in the Ant log.

Parameters: logError get in the ant log the messages coming from stderr in the case that fork = true.

setMaxmemory

public void setMaxmemory(String max)
Corresponds to -mx or -Xmx depending on VM version.

Parameters: max max memory parameter.

setNewenvironment

public void setNewenvironment(boolean newenv)
If true, use a completely new environment.

Will be ignored if we are not forking a new VM.

Parameters: newenv if true, use a completely new environment.

Since: Ant 1.5

setOutput

public void setOutput(File out)
Set the File to which the output of the process is redirected.

Parameters: out the output File.

setOutputproperty

public void setOutputproperty(String outputProp)
Set the property name whose value should be set to the output of the process.

Parameters: outputProp property name.

setResultProperty

public void setResultProperty(String resultProperty)
Set the name of the property in which the return code of the command should be stored. Only of interest if failonerror=false.

Parameters: resultProperty name of property.

Since: Ant 1.6

setSpawn

public void setSpawn(boolean spawn)
Set whether or not you want the process to be spawned; default is not spawned.

Parameters: spawn if true you do not want Ant to wait for the end of the process.

Since: Ant 1.6

setTimeout

public void setTimeout(Long value)
Set the timeout in milliseconds after which the process will be killed.

Parameters: value timeout in milliseconds.

Since: Ant 1.5

setupRedirector

protected void setupRedirector()
Set up properties on the redirector that we needed to store locally.