Package org.apache.tools.ant.taskdefs
Class Java
java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.Task
org.apache.tools.ant.taskdefs.Java
- 
Field SummaryFieldsFields inherited from class org.apache.tools.ant.ProjectComponentdescription, location, project
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddAssertions(Assertions asserts) Add assertions to enable in this program (if fork=true).voidaddConfiguredRedirector(RedirectorElement redirectorElement) Add aRedirectorElementto this task.voidAdd an environment variable.voidAdd a system property.voidaddSyspropertyset(PropertySet sysp) Add a set of properties as system properties.protected voidCheck configuration.voidClear out the arguments to this java task.Add a command-line argument.Add a path to the bootclasspath.Add a path to the classpath.Adds a JVM argument.Add a path to the modulepath.Set the permissions for the application run inside the same JVM.Add a path to the upgrademodulepath.protected ExecuteWatchdogCreate the Watchdog to kill a runaway process.voidexecute()Do the execution.intDo the execution and return a return code.protected intexecuteJava(CommandlineJava commandLine) Execute the specified CommandlineJava.Accessor to the command line.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 voidExecutes 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.voidDeprecated: use nested arg instead.voidSet the Java class to execute.voidsetClasspath(Path s) Set the classpath to be used when running the Java class.voidSet 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 bootclasspath.voidSet the working directory of the process.voidsetDiscardError(boolean discard) Whether error output should be discarded.voidsetDiscardOutput(boolean discard) Whether output should be discarded.voidSet 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.voidSet the input to use for the task.voidsetInputString(String inputString) Set the string to use as input.voidSet the location of the JAR file to execute.voidSet 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.voidSet the Java module to execute.voidsetModulepath(Path mp) Set the modulepath to be used when running the Java class.voidSet the modulepath to use by reference.voidsetNewenvironment(boolean newenv) If true, use a completely new environment.voidSet 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.voidsetSourceFile(String sourceFile) Set the Java source-file to execute.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 voidSet up properties on the redirector that we needed to store locally.Methods inherited from class org.apache.tools.ant.TaskbindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskTypeMethods inherited from class org.apache.tools.ant.ProjectComponentclone, getDescription, getLocation, getProject, setDescription, setLocation, setProject
- 
Field Details- 
redirector
- 
redirectorElement
 
- 
- 
Constructor Details- 
Javapublic Java()Normal constructor
- 
Java
 
- 
- 
Method Details- 
executeDo the execution.- Overrides:
- executein class- Task
- Throws:
- BuildException- if failOnError is set to true and the application returns a nonzero result code.
 
- 
executeJavaDo 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.
 
- 
checkConfigurationCheck configuration.- Throws:
- BuildException- if required parameters are missing.
 
- 
executeJavaExecute the specified CommandlineJava.- Parameters:
- commandLine- CommandLineJava instance.
- Returns:
- the exit value of the process if forked, 0 otherwise.
 
- 
setSpawnpublic 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
 
- 
setClasspathSet the classpath to be used when running the Java class.- Parameters:
- s- an Ant Path object containing the classpath.
 
- 
createClasspath
- 
createBootclasspathAdd a path to the bootclasspath.- Returns:
- created bootclasspath.
- Since:
- Ant 1.6
 
- 
setModulepathSet the modulepath to be used when running the Java class.- Parameters:
- mp- an Ant Path object containing the modulepath.
- Since:
- 1.9.7
 
- 
createModulepathAdd a path to the modulepath.- Returns:
- created modulepath.
- Since:
- 1.9.7
 
- 
setModulepathRefSet the modulepath to use by reference.- Parameters:
- r- a reference to an existing modulepath.
- Since:
- 1.9.7
 
- 
createUpgrademodulepathAdd a path to the upgrademodulepath.- Returns:
- created upgrademodulepath.
- Since:
- 1.9.7
 
- 
createPermissionsSet the permissions for the application run inside the same JVM.- Returns:
- Permissions.
- Since:
- Ant 1.6
 
- 
setClasspathRefSet the classpath to use by reference.- Parameters:
- r- a reference to an existing classpath.
 
- 
setJarSet the location of the JAR file to execute.- Parameters:
- jarfile- the jarfile to execute.
- Throws:
- BuildException- if there is also a- classname,- moduleor- sourcefileattribute specified
 
- 
setClassnameSet the Java class to execute.- Parameters:
- s- the name of the main class.
- Throws:
- BuildException- if there is also a- jaror- sourcefileattribute specified
 
- 
setModuleSet the Java module to execute.- Parameters:
- module- the name of the module.
- Throws:
- BuildException- if there is also a- jaror- sourcefileattribute specified
- Since:
- 1.9.7
 
- 
setSourceFileSet the Java source-file to execute. Support for single file source program execution, in Java, is only available since Java 11.- Parameters:
- sourceFile- The path to the source file
- Throws:
- BuildException- if there is also a- jar,- classnameor- moduleattribute specified
- Since:
- Ant 1.10.5
 
- 
setArgsDeprecated: use nested arg instead. Set the command line arguments for the class.- Parameters:
- s- arguments.
 
- 
setCloneVmpublic 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 bootclasspath.Doesn't have any effect unless fork is true. - Parameters:
- cloneVm- if true copy system properties.
- Since:
- Ant 1.7
 
- 
createArg
- 
setResultPropertySet 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
 
- 
maybeSetResultPropertyValueprotected void maybeSetResultPropertyValue(int result) Helper method to set result property to the passed in value if appropriate.- Parameters:
- result- the exit code
 
- 
setForkpublic void setFork(boolean s) If true, execute in a new VM.- Parameters:
- s- do you want to run Java in a new VM.
 
- 
setJvmargsSet the command line arguments for the JVM.- Parameters:
- s- jvmargs.
 
- 
createJvmarg
- 
setJvmSet the command used to start the VM (only if forking).- Parameters:
- s- command to start the VM.
 
- 
addSyspropertyAdd a system property.- Parameters:
- sysp- system property.
 
- 
addSyspropertysetAdd a set of properties as system properties.- Parameters:
- sysp- set of properties to add.
- Since:
- Ant 1.6
 
- 
setFailonerrorpublic 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.
 
- 
setDirSet the working directory of the process.- Parameters:
- d- working directory.
 
- 
setOutputSet the File to which the output of the process is redirected.- Parameters:
- out- the output File.
 
- 
setInputSet the input to use for the task.- Parameters:
- input- name of the input file.
 
- 
setInputStringSet the string to use as input.- Parameters:
- inputString- the string which is used as the input source.
 
- 
setLogErrorpublic 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.
 
- 
setErrorSet the File to which the error stream of the process is redirected.- Parameters:
- error- file getting the error stream.
- Since:
- Ant 1.6
 
- 
setOutputpropertySet the property name whose value should be set to the output of the process.- Parameters:
- outputProp- property name.
 
- 
setErrorPropertySet the property name whose value should be set to the error of the process.- Parameters:
- errorProperty- property name.
- Since:
- Ant 1.6
 
- 
setMaxmemoryCorresponds to -mx or -Xmx depending on VM version.- Parameters:
- max- max memory parameter.
 
- 
setJVMVersion
- 
addEnvAdd an environment variable.Will be ignored if we are not forking a new VM. - Parameters:
- var- new environment variable.
- Since:
- Ant 1.5
 
- 
setNewenvironmentpublic 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
 
- 
setAppendpublic void setAppend(boolean append) If true, append output to existing file.- Parameters:
- append- if true, append output to existing file.
- Since:
- Ant 1.5
 
- 
setDiscardOutputpublic void setDiscardOutput(boolean discard) Whether output should be discarded.Defaults to false. - Parameters:
- discard- if true output streams are discarded.
- Since:
- Ant 1.10.10
- See Also:
 
- 
setDiscardErrorpublic void setDiscardError(boolean discard) Whether error output should be discarded.Defaults to false. - Parameters:
- discard- if true error streams are discarded.
- Since:
- Ant 1.10.10
- See Also:
 
- 
setTimeoutSet the timeout in milliseconds after which the process will be killed.- Parameters:
- value- timeout in milliseconds.
- Since:
- Ant 1.5
 
- 
addAssertionsAdd assertions to enable in this program (if fork=true).- Parameters:
- asserts- assertion set.
- Since:
- Ant 1.6
 
- 
addConfiguredRedirectorAdd aRedirectorElementto this task.- Parameters:
- redirectorElement-- RedirectorElement.
 
- 
handleOutputPass output sent to System.out to specified output file.- Overrides:
- handleOutputin class- Task
- Parameters:
- output- a string of output on its way to the handlers.
- Since:
- Ant 1.5
 
- 
handleInputHandle an input request by this task.- Overrides:
- handleInputin class- 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
 
- 
handleFlushPass output sent to System.out to specified output file.- Overrides:
- handleFlushin class- Task
- Parameters:
- output- string of output on its way to its handlers.
- Since:
- Ant 1.5.2
 
- 
handleErrorOutputHandle output sent to System.err.- Overrides:
- handleErrorOutputin class- Task
- Parameters:
- output- string of stderr.
- Since:
- Ant 1.5
 
- 
handleErrorFlushHandle output sent to System.err and flush the stream.- Overrides:
- handleErrorFlushin class- Task
- Parameters:
- output- string of stderr.
- Since:
- Ant 1.5.2
 
- 
setupRedirectorprotected void setupRedirector()Set up properties on the redirector that we needed to store locally.
- 
runExecutes 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.
 
- 
clearArgspublic void clearArgs()Clear out the arguments to this java task.
- 
createWatchdogCreate the Watchdog to kill a runaway process.- Returns:
- new watchdog.
- Throws:
- BuildException- under unknown circumstances.
- Since:
- Ant 1.5
 
- 
getCommandLineAccessor to the command line.- Returns:
- the current command line.
- Since:
- 1.6.3
 
- 
getSysPropertiesGet the system properties of the command line.- Returns:
- the current properties of this java invocation.
- Since:
- 1.6.3
 
 
-