Package org.apache.tools.ant.types
Class CommandlineJava
- java.lang.Object
- 
- org.apache.tools.ant.types.CommandlineJava
 
- 
- All Implemented Interfaces:
- java.lang.Cloneable
 
 public class CommandlineJava extends java.lang.Object implements java.lang.CloneableA representation of a Java command line that is a composite of 2Commandlines. One is used for the vm/options and one for the classname/arguments. It provides specific methods for a Java command line.
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classCommandlineJava.SysPropertiesSpecialized Environment class for System properties.
 - 
Constructor SummaryConstructors Constructor Description CommandlineJava()Constructor uses the VM we are running on now.
 - 
Method SummaryModifier and Type Method Description voidaddSysproperties(CommandlineJava.SysProperties sysp)Add a set of system properties.voidaddSysproperty(Environment.Variable sysp)Add a system property.voidaddSyspropertyset(PropertySet sysp)Add a set of system properties.voidclearJavaArgs()Clear out the java arguments.java.lang.Objectclone()Deep clone the object.Commandline.ArgumentcreateArgument()Create a new argument to the java program.PathcreateBootclasspath(Project p)Create a boot classpath.PathcreateClasspath(Project p)Create a classpath.PathcreateModulepath(Project p)Create a modulepath.PathcreateUpgrademodulepath(Project p)Create an upgrademodulepath.Commandline.ArgumentcreateVmArgument()Create a new JVM argument.java.lang.StringdescribeCommand()Return a String that describes the command and arguments suitable for verbose output before a call toRuntime.exec(String[]).java.lang.StringdescribeJavaCommand()Return a String that describes the java command and arguments for in-VM executions.protected CommandlinegetActualVMCommand()Get the VM command parameters, including memory settings.AssertionsgetAssertions()Get the current assertions.PathgetBootclasspath()Get the boot classpath.java.lang.StringgetClassname()Get the name of the class to be run.PathgetClasspath()Get the classpath for the command.java.lang.String[]getCommandline()Get the command line to run a Java vm.java.lang.StringgetJar()Get the name of the jar to be run.CommandlinegetJavaCommand()Get the Java command to be used.java.lang.StringgetModule()Get the name of the module to be run.PathgetModulepath()Get the modulepath.java.lang.StringgetSourceFile()CommandlineJava.SysPropertiesgetSystemProperties()Get the system properties object.PathgetUpgrademodulepath()Get the upgrademodulepath.CommandlinegetVmCommand()Get the VM command, including memory.java.lang.StringgetVmversion()Get the vm version.protected booleanhaveBootclasspath(boolean log)Determine whether the bootclasspath has been specified, and whether it shall really be used (build.sysclasspath could be set or the VM may not support it).booleanhaveClasspath()Determine whether the classpath has been specified, and whether it shall really be used or be nulled by build.sysclasspath.booleanhaveModulepath()Determine whether the modulepath has been specified.booleanhaveUpgrademodulepath()Determine whether the upgrademodulepath has been specified.voidrestoreSystemProperties()Restore the cached system properties.voidsetAssertions(Assertions assertions)Add an assertion set to the command.voidsetClassname(java.lang.String classname)Set the classname to execute.voidsetCloneVm(boolean cloneVm)Set whether system properties will be copied to the cloned VM--as well as the bootclasspath unless you have explicitly specified a bootclasspath.voidsetJar(java.lang.String jarpathname)Set a jar file to execute via the -jar option.voidsetMaxmemory(java.lang.String max)Specify max memory of the JVM.voidsetModule(java.lang.String module)Set the module to execute.voidsetSourceFile(java.lang.String sourceFile)Set the source-file, to execute as single file source programs, a feature, available since Java 11.voidsetSystemProperties()Cache current system properties and set them to those in this Java command.voidsetVm(java.lang.String vm)Set the executable used to start the new JVM.voidsetVmversion(java.lang.String value)Set the JVM version required.intsize()Deprecated.since 1.7.java.lang.StringtoString()Get a string description.
 
- 
- 
- 
Method Detail- 
createArgumentpublic Commandline.Argument createArgument() Create a new argument to the java program.- Returns:
- an argument to be configured.
 
 - 
createVmArgumentpublic Commandline.Argument createVmArgument() Create a new JVM argument.- Returns:
- an argument to be configured.
 
 - 
addSyspropertypublic void addSysproperty(Environment.Variable sysp) Add a system property.- Parameters:
- sysp- a property to be set in the JVM.
 
 - 
addSyspropertysetpublic void addSyspropertyset(PropertySet sysp) Add a set of system properties.- Parameters:
- sysp- a set of properties.
 
 - 
addSyspropertiespublic void addSysproperties(CommandlineJava.SysProperties sysp) Add a set of system properties.- Parameters:
- sysp- a set of properties.
- Since:
- Ant 1.6.3
 
 - 
setVmpublic void setVm(java.lang.String vm) Set the executable used to start the new JVM.- Parameters:
- vm- the executable to use.
 
 - 
setVmversionpublic void setVmversion(java.lang.String value) Set the JVM version required.- Parameters:
- value- the version required.
 
 - 
setCloneVmpublic void setCloneVm(boolean cloneVm) Set whether system properties will be copied to the cloned VM--as well as the bootclasspath unless you have explicitly specified a bootclasspath.- Parameters:
- cloneVm- if true copy the system properties.
- Since:
- Ant 1.7
 
 - 
getAssertionspublic Assertions getAssertions() Get the current assertions.- Returns:
- assertions or null.
 
 - 
setAssertionspublic void setAssertions(Assertions assertions) Add an assertion set to the command.- Parameters:
- assertions- assertions to make.
 
 - 
setJarpublic void setJar(java.lang.String jarpathname) Set a jar file to execute via the -jar option.- Parameters:
- jarpathname- the pathname of the jar to execute.
 
 - 
getJarpublic java.lang.String getJar() Get the name of the jar to be run.- Returns:
- the pathname of the jar file to run via -jar option
 or nullif there is no jar to run.
- See Also:
- getClassname()
 
 - 
setClassnamepublic void setClassname(java.lang.String classname) Set the classname to execute.- Parameters:
- classname- the fully qualified classname.
 
 - 
getClassnamepublic java.lang.String getClassname() Get the name of the class to be run.- Returns:
- the name of the class to run or nullif there is no class.
- See Also:
- getJar()
 
 - 
setSourceFilepublic void setSourceFile(java.lang.String sourceFile) Set the source-file, to execute as single file source programs, a feature, available since Java 11.- Parameters:
- sourceFile- The path to the source file
- Since:
- Ant 1.10.5
 
 - 
getSourceFilepublic java.lang.String getSourceFile() - Returns:
- Returns the source-file to execute, if this command line has
 been configured for single file source program execution. Else returns null.
- Since:
- Ant 1.10.5
 
 - 
setModulepublic void setModule(java.lang.String module) Set the module to execute.- Parameters:
- module- the module name.
- Since:
- 1.9.7
 
 - 
getModulepublic java.lang.String getModule() Get the name of the module to be run.- Returns:
- the name of the module to run or nullif there is no module.
- Since:
- 1.9.7
- See Also:
- getJar(),- getClassname()
 
 - 
createClasspathpublic Path createClasspath(Project p) Create a classpath.- Parameters:
- p- the project to use to create the path.
- Returns:
- a path to be configured.
 
 - 
createBootclasspathpublic Path createBootclasspath(Project p) Create a boot classpath.- Parameters:
- p- the project to use to create the path.
- Returns:
- a path to be configured.
- Since:
- Ant 1.6
 
 - 
createModulepathpublic Path createModulepath(Project p) Create a modulepath.- Parameters:
- p- the project to use to create the path.
- Returns:
- a path to be configured.
- Since:
- 1.9.7
 
 - 
createUpgrademodulepathpublic Path createUpgrademodulepath(Project p) Create an upgrademodulepath.- Parameters:
- p- the project to use to create the path.
- Returns:
- a path to be configured.
- Since:
- 1.9.7
 
 - 
getVmversionpublic java.lang.String getVmversion() Get the vm version.- Returns:
- the vm version.
 
 - 
getCommandlinepublic java.lang.String[] getCommandline() Get the command line to run a Java vm.- Returns:
- the list of all arguments necessary to run the vm.
 
 - 
setMaxmemorypublic void setMaxmemory(java.lang.String max) Specify max memory of the JVM. -mx or -Xmx depending on VM version.- Parameters:
- max- the string to pass to the jvm to specify the max memory.
 
 - 
toStringpublic java.lang.String toString() Get a string description.- Overrides:
- toStringin class- java.lang.Object
- Returns:
- the command line as a string.
 
 - 
describeCommandpublic java.lang.String describeCommand() Return a String that describes the command and arguments suitable for verbose output before a call toRuntime.exec(String[]).- Returns:
- the description string.
- Since:
- Ant 1.5
 
 - 
describeJavaCommandpublic java.lang.String describeJavaCommand() Return a String that describes the java command and arguments for in-VM executions.The class name is the executable in this context. - Returns:
- the description string.
- Since:
- Ant 1.5
 
 - 
getActualVMCommandprotected Commandline getActualVMCommand() Get the VM command parameters, including memory settings.- Returns:
- the VM command parameters.
 
 - 
size@Deprecated public int size() Deprecated.since 1.7. Please don't use this, it effectively creates the entire command.Get the size of the java command line. This is a fairly intensive operation, as it has to evaluate the size of many components.- Returns:
- the total number of arguments in the java command line.
- See Also:
- getCommandline()
 
 - 
getJavaCommandpublic Commandline getJavaCommand() Get the Java command to be used.- Returns:
- the java command--not a clone.
 
 - 
getVmCommandpublic Commandline getVmCommand() Get the VM command, including memory.- Returns:
- A deep clone of the instance's VM command, with memory settings added.
 
 - 
getClasspathpublic Path getClasspath() Get the classpath for the command.- Returns:
- the classpath or null.
 
 - 
getBootclasspathpublic Path getBootclasspath() Get the boot classpath.- Returns:
- boot classpath or null.
 
 - 
getModulepathpublic Path getModulepath() Get the modulepath.- Returns:
- modulepath or null.
- Since:
- 1.9.7
 
 - 
getUpgrademodulepathpublic Path getUpgrademodulepath() Get the upgrademodulepath.- Returns:
- upgrademodulepath or null.
- Since:
- 1.9.7
 
 - 
setSystemPropertiespublic void setSystemProperties() throws BuildExceptionCache current system properties and set them to those in this Java command.- Throws:
- BuildException- if Security prevented this operation.
 
 - 
restoreSystemPropertiespublic void restoreSystemProperties() throws BuildExceptionRestore the cached system properties.- Throws:
- BuildException- if Security prevented this operation, or there was no system properties to restore
 
 - 
getSystemPropertiespublic CommandlineJava.SysProperties getSystemProperties() Get the system properties object.- Returns:
- The system properties object.
 
 - 
clonepublic java.lang.Object clone() throws java.lang.CloneNotSupportedExceptionDeep clone the object.- Overrides:
- clonein class- java.lang.Object
- Returns:
- a CommandlineJava object.
- Throws:
- BuildException- if anything went wrong.
- java.lang.CloneNotSupportedException- never.
 
 - 
clearJavaArgspublic void clearJavaArgs() Clear out the java arguments.
 - 
haveClasspathpublic boolean haveClasspath() Determine whether the classpath has been specified, and whether it shall really be used or be nulled by build.sysclasspath.- Returns:
- true if the classpath is to be used.
- Since:
- Ant 1.6
 
 - 
haveBootclasspathprotected boolean haveBootclasspath(boolean log) Determine whether the bootclasspath has been specified, and whether it shall really be used (build.sysclasspath could be set or the VM may not support it).- Parameters:
- log- whether to log a warning if a bootclasspath has been specified but will be ignored.
- Returns:
- true if the bootclasspath is to be used.
- Since:
- Ant 1.6
 
 - 
haveModulepathpublic boolean haveModulepath() Determine whether the modulepath has been specified.- Returns:
- true if the modulepath is to be used.
- Since:
- 1.9.7
 
 - 
haveUpgrademodulepathpublic boolean haveUpgrademodulepath() Determine whether the upgrademodulepath has been specified.- Returns:
- true if the upgrademodulepath is to be used.
- Since:
- 1.9.7
 
 
- 
 
-