org.apache.tools.ant.taskdefs

Class Java

Known Direct Subclasses:
StyleBook, Test

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

Field Summary

protected Redirector
redirector
protected RedirectorElement
redirectorElement

Fields inherited from class org.apache.tools.ant.Task

description, location, target, taskName, taskType, wrapper

Fields inherited from class org.apache.tools.ant.ProjectComponent

project

Method Summary

void
addAssertions(Assertions asserts)
assertions to enable in this program (if fork=true)
void
addConfiguredRedirector(RedirectorElement redirectorElement)
Add a RedirectorElement to this task.
void
addEnv(Environment.Variable var)
Adds an environment variable.
void
addSysproperty(Environment.Variable sysp)
Adds a system property.
void
addSyspropertyset(PropertySet sysp)
Adds a set of properties as system properties.
void
clearArgs()
Clear out the arguments to this java task.
Commandline.Argument
createArg()
Adds a command-line argument.
Path
createBootclasspath()
Adds a path to the bootclasspath.
Path
createClasspath()
Adds a path to the classpath.
Commandline.Argument
createJvmarg()
Adds a JVM argument.
Permissions
createPermissions()
Sets the permissions for the application run inside the same JVM.
protected ExecuteWatchdog
createWatchdog()
Create the Watchdog to kill a runaway process.
void
execute()
Do the execution.
int
executeJava()
Do the execution and return a return code.
protected void
handleErrorFlush(String output)
Handle output sent to System.err and flush the stream.
protected void
handleErrorOutput(String output)
Handle output sent to System.err
protected void
handleFlush(String output)
Pass output sent to System.out to specified output file.
int
handleInput(byte[] buffer, int offset, int length)
Handle an input request by this task
protected void
handleOutput(String output)
Pass output sent to System.out to specified output file.
protected void
maybeSetResultPropertyValue(int result)
helper method to set result property to the passed in value if appropriate
protected void
run(String classname, Vector args)
Executes the given classname with the given arguments as it was a command line application.
void
setAppend(boolean append)
If true, append output to existing file.
void
setArgs(String s)
Deprecated: use nested arg instead.
void
setClassname(String s)
Sets the Java class to execute.
void
setClasspath(Path s)
Set the classpath to be used when running the Java class
void
setClasspathRef(Reference r)
Classpath to use, by reference.
void
setDir(File d)
The working directory of the process
void
setError(File error)
File the error stream of the process is redirected to.
void
setErrorProperty(String errorProperty)
Property name whose value should be set to the error of the process.
void
setFailonerror(boolean fail)
If true, then fail if the command exits with a returncode other than 0
void
setFork(boolean s)
If true, execute in a new VM.
void
setInput(File input)
Set the input to use for the task
void
setInputString(String inputString)
Set the string to use as input
void
setJVMVersion(String value)
Sets the JVM version.
void
setJar(File jarfile)
The location of the JAR file to execute.
void
setJvm(String s)
Set the command used to start the VM (only if forking).
void
setJvmargs(String s)
Set the command line arguments for the JVM.
void
setLogError(boolean logError)
Controls whether error output of exec is logged.
void
setMaxmemory(String max)
Corresponds to -mx or -Xmx depending on VM version.
void
setNewenvironment(boolean newenv)
If true, use a completely new environment.
void
setOutput(File out)
File the output of the process is redirected to.
void
setOutputproperty(String outputProp)
Property name whose value should be set to the output of the process.
void
setResultProperty(String resultProperty)
The name of a property in which the return code of the command should be stored.
void
setSpawn(boolean spawn)
set whether or not you want the process to be spawned default is not spawned
void
setTimeout(Long value)
Timeout in milliseconds after which the process will be killed.
protected void
setupRedirector()
Set up properties on the redirector that we needed to store locally.

Methods inherited from class org.apache.tools.ant.Task

execute, getDescription, getLocation, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, maybeConfigure, perform, reconfigure, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType

Methods inherited from class org.apache.tools.ant.ProjectComponent

getProject, log, log, setProject

Field Details

redirector

protected Redirector redirector


redirectorElement

protected RedirectorElement redirectorElement

Method Details

addAssertions

public void addAssertions(Assertions asserts)
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)
Adds 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)
Adds a system property.

Parameters:
sysp - system property


addSyspropertyset

public void addSyspropertyset(PropertySet sysp)
Adds 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()
Adds a command-line argument.

Returns:
created argument


createBootclasspath

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

Returns:
created bootclasspath

Since:
Ant 1.6


createClasspath

public Path createClasspath()
Adds 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()
Sets the permissions for the application run inside the same JVM.

Returns:
.

Since:
Ant 1.6


createWatchdog

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

Returns:
new watchdog

Throws:
BuildException - under unknown circumstances

Since:
Ant 1.5


execute

public void execute()
            throws BuildException
Do the execution.
Overrides:
execute in interface Task

Throws:
BuildException - if failOnError is set to true and the application returns a non 0 result code


executeJava

public int executeJava()
            throws BuildException
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").

Throws:
BuildException - if required parameters are missing


handleErrorFlush

protected void handleErrorFlush(String output)
Handle output sent to System.err and flush the stream.
Overrides:
handleErrorFlush in interface Task

Parameters:
output - string of stderr

Since:
Ant 1.5.2


handleErrorOutput

protected void handleErrorOutput(String output)
Handle output sent to System.err
Overrides:
handleErrorOutput in interface Task

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.
Overrides:
handleFlush in interface Task

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)
            throws IOException
Handle an input request by this task
Overrides:
handleInput in interface 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

Since:
Ant 1.6


handleOutput

protected void handleOutput(String output)
Pass output sent to System.out to specified output file.
Overrides:
handleOutput in interface Task

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)
            throws BuildException
Executes the given classname with the given arguments as it was a command line application.

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

Throws:
BuildException - in case of IO Exception 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


setClassname

public void setClassname(String s)
            throws BuildException
Sets 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)
Classpath to use, by reference.

Parameters:
r - a reference to an existing classpath


setDir

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

Parameters:
d - working directory


setError

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

Parameters:
error - file getting the error stream

Since:
ant 1.6


setErrorProperty

public void setErrorProperty(String errorProperty)
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 0

Parameters:
fail - if true fail the build when the command exits with a non zero 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


setJVMVersion

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

Parameters:
value - JVM version


setJar

public void setJar(File jarfile)
            throws BuildException
The location of the JAR file to execute.

Parameters:
jarfile - the jarfile that one wants 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


setLogError

public void setLogError(boolean logError)
Controls 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)
File the output of the process is redirected to.

Parameters:
out - name of the output file


setOutputproperty

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

Parameters:
outputProp - property name


setResultProperty

public void setResultProperty(String resultProperty)
The name of a 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)
Timeout in milliseconds after which the process will be killed.

Parameters:
value - time out in milliseconds

Since:
Ant 1.5


setupRedirector

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


Copyright B) 2000-2005 Apache Software Foundation. All Rights Reserved.