Top Description Inners Fields Constructors Methods
org.apache.tools.ant.types

public Class CommandlineJava

extends Object
implements Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable
Imports
java.util.LinkedList, .List, .ListIterator, .Properties, .Vector, org.apache.tools.ant.BuildException, .Project, org.apache.tools.ant.util.JavaEnvUtils

A representation of a Java command line that is a composite of 2 Commandlines. One is used for the vm/options and one for the classname/arguments. It provides specific methods for a Java command line.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum
public static class
CommandlineJava.SysProperties

Specialized Environment class for System properties.

Field Summary

Modifier and TypeField and Description
private Assertions
assertions

any assertions to make?

private Path
private Path
private boolean
cloneVm

Whether system properties and bootclasspath shall be cloned.

private CommandlineJava.ExecutableType
executableType

Indicate whether it will execute a jar file, module or main class.

private Commandline
javaCommand

actual java commands

private String
private Path
private CommandlineJava.SysProperties
sysProperties

properties to add using -D

private Path
private Commandline
vmCommand

commands to the JVM

private String

Constructor Summary

AccessConstructor and Description
public
CommandlineJava()

Constructor uses the VM we are running on now.

Method Summary

Modifier and TypeMethod and Description
private void
addCommandsToList(final ListIterator<String>
an iterator that supports the add method.
listIterator
)

Add all the commands to a list identified by the iterator passed in.

public void
addSysproperties(CommandlineJava.SysProperties
a set of properties.
sysp
)

Add a set of system properties.

public void
addSysproperty(Environment.Variable
a property to be set in the JVM.
sysp
)

Add a system property.

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

Add a set of system properties.

private Path
calculateBootclasspath(boolean
whether to write messages to the log.
log
)

Calculate the bootclasspath based on the bootclasspath specified, the build.sysclasspath and ant.build.clonevm magic properties as well as the cloneVm attribute.

public void
clearJavaArgs()

Clear out the java arguments.

public Object

Returns:

a CommandlineJava object.
clone
()

Overrides java.lang.Object.clone.

Deep clone the object.
public Commandline.Argument

Returns:

an argument to be configured.
createArgument
()

Create a new argument to the java program.

public Path

Returns:

a path to be configured.
createBootclasspath
(Project
the project to use to create the path.
p
)

Create a boot classpath.

public Path

Returns:

a path to be configured.
createClasspath
(Project
the project to use to create the path.
p
)

Create a classpath.

private static String

Returns:

the main module with optional classname command line argument.
createModuleClassPair
(final String
the module name.
module
,
final String
the classname or null.
classname
)

Creates JDK 9 main module command line argument.

public Path

Returns:

a path to be configured.
createModulepath
(Project
the project to use to create the path.
p
)

Create a modulepath.

public Path

Returns:

a path to be configured.
createUpgrademodulepath
(Project
the project to use to create the path.
p
)

Create an upgrademodulepath.

public Commandline.Argument

Returns:

an argument to be configured.
createVmArgument
()

Create a new JVM argument.

public String

Returns:

the description string.
describeCommand
()

Return a String that describes the command and arguments suitable for verbose output before a call to Runtime.exec(String[]).

public String

Returns:

the description string.
describeJavaCommand
()

Return a String that describes the java command and arguments for in-VM executions.

protected Commandline

Returns:

the VM command parameters.
getActualVMCommand
()

Get the VM command parameters, including memory settings.

public Assertions

Returns:

assertions or null.
getAssertions
()

Get the current assertions.

public Path

Returns:

boot classpath or null.
getBootclasspath
()

Get the boot classpath.

public String

Returns:

the name of the class to run or null if there is no class.
getClassname
()

Get the name of the class to be run.

public Path

Returns:

the classpath or null.
getClasspath
()

Get the classpath for the command.

public String[]

Returns:

the list of all arguments necessary to run the vm.
getCommandline
()

Get the command line to run a Java vm.

public String

Returns:

the pathname of the jar file to run via -jar option or null if there is no jar to run.
getJar
()

Get the name of the jar to be run.

public Commandline

Returns:

the java command--not a clone.
getJavaCommand
()

Get the Java command to be used.

public String

Returns:

the name of the module to run or null if there is no module.
getModule
()

Get the name of the module to be run.

public Path

Returns:

modulepath or null.
getModulepath
()

Get the modulepath.

public String

Returns:

Returns the source-file to execute, if this command line has been configured for single file source program execution. Else returns null.
getSourceFile
()

public CommandlineJava.SysProperties

Returns:

The system properties object.
getSystemProperties
()

Get the system properties object.

public Path

Returns:

upgrademodulepath or null.
getUpgrademodulepath
()

Get the upgrademodulepath.

public Commandline

Returns:

A deep clone of the instance's VM command, with memory settings added.
getVmCommand
()

Get the VM command, including memory.

public String

Returns:

the vm version.
getVmversion
()

Get the vm version.

protected boolean

Returns:

true if the bootclasspath is to be used.
haveBootclasspath
(boolean
whether to log a warning if a bootclasspath has been specified but will be ignored.
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).

public boolean

Returns:

true if the classpath is to be used.
haveClasspath
()

Determine whether the classpath has been specified, and whether it shall really be used or be nulled by build.sysclasspath.

public boolean

Returns:

true if the modulepath is to be used.
haveModulepath
()

Determine whether the modulepath has been specified.

public boolean

Returns:

true if the upgrademodulepath is to be used.
haveUpgrademodulepath
()

Determine whether the upgrademodulepath has been specified.

private boolean

Returns:

boolean.
isCloneVm
()

Find out whether either of the cloneVm attribute or the magic property ant.build.clonevm has been set.

private static String

Returns:

the classname or null.
parseClassFromModuleClassPair
(final String
a module with optional classname or null.
moduleClassPair
)

Parses a classname from JDK 9 main module command line argument.

private static String

Returns:

the module name or null.
parseModuleFromModuleClassPair
(final String
a module with optional classname or null.
moduleClassPair
)

Parses a module name from JDK 9 main module command line argument.

public void
restoreSystemProperties()

Restore the cached system properties.

public void
setAssertions(Assertions
assertions to make.
assertions
)

Add an assertion set to the command.

public void
setClassname(String
the fully qualified classname.
classname
)

Set the classname to execute.

public void
setCloneVm(boolean
if true copy the system properties.
cloneVm
)

Set whether system properties will be copied to the cloned VM--as well as the bootclasspath unless you have explicitly specified a bootclasspath.

public void
setJar(String
the pathname of the jar to execute.
jarpathname
)

Set a jar file to execute via the -jar option.

public void
setMaxmemory(String
the string to pass to the jvm to specify the max memory.
max
)

Specify max memory of the JVM.

public void
setModule(final String
the module name.
module
)

Set the module to execute.

public void
setSourceFile(final String
The path to the source file
sourceFile
)

Set the source-file, to execute as single file source programs, a feature, available since Java 11.

public void
setSystemProperties()

Cache current system properties and set them to those in this Java command.

public void
setVm(String
the executable to use.
vm
)

Set the executable used to start the new JVM.

public void
setVmversion(String
the version required.
value
)

Set the JVM version required.

public int

Returns:

the total number of arguments in the java command line.
size
()

Deprecated since 1.7. Please don't use this, it effectively creates the entire command.
Get the size of the java command line.
public String

Returns:

the command line as a string.
toString
()

Overrides java.lang.Object.toString.

Get a string description.
Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

assertionsback to summary
private Assertions assertions

any assertions to make? Currently only supported in forked JVMs

bootclasspathback to summary
private Path bootclasspath
classpathback to summary
private Path classpath
cloneVmback to summary
private boolean cloneVm

Whether system properties and bootclasspath shall be cloned.

Since
Ant 1.7
executableTypeback to summary
private CommandlineJava.ExecutableType executableType

Indicate whether it will execute a jar file, module or main class. In this case of jar the first vm option must be a -jar and the 'executable' is a jar file. In case of module the first vm option is -m and the 'executable' is 'module/mainClass'.

javaCommandback to summary
private Commandline javaCommand

actual java commands

maxMemoryback to summary
private String maxMemory
modulepathback to summary
private Path modulepath
sysPropertiesback to summary
private CommandlineJava.SysProperties sysProperties

properties to add using -D

upgrademodulepathback to summary
private Path upgrademodulepath
vmCommandback to summary
private Commandline vmCommand

commands to the JVM

vmVersionback to summary
private String vmVersion

Constructor Detail

CommandlineJavaback to summary
public CommandlineJava()

Constructor uses the VM we are running on now.

Method Detail

addCommandsToListback to summary
private void addCommandsToList(final ListIterator<String> listIterator)

Add all the commands to a list identified by the iterator passed in.

Parameters
listIterator:ListIterator<String>

an iterator that supports the add method.

Since
Ant 1.6
addSyspropertiesback to summary
public void addSysproperties(CommandlineJava.SysProperties sysp)

Add a set of system properties.

Parameters
sysp:CommandlineJava.SysProperties

a set of properties.

Since
Ant 1.6.3
addSyspropertyback to summary
public void addSysproperty(Environment.Variable sysp)

Add a system property.

Parameters
sysp:Environment.Variable

a property to be set in the JVM.

addSyspropertysetback to summary
public void addSyspropertyset(PropertySet sysp)

Add a set of system properties.

Parameters
sysp:PropertySet

a set of properties.

calculateBootclasspathback to summary
private Path calculateBootclasspath(boolean log)

Calculate the bootclasspath based on the bootclasspath specified, the build.sysclasspath and ant.build.clonevm magic properties as well as the cloneVm attribute.

Parameters
log:boolean

whether to write messages to the log.

Since
Ant 1.7
clearJavaArgsback to summary
public void clearJavaArgs()

Clear out the java arguments.

cloneback to summary
public Object clone() throws CloneNotSupportedException

Overrides java.lang.Object.clone.

Deep clone the object.

Returns:Object

a CommandlineJava object.

Annotations
@Override
Exceptions
CloneNotSupportedException:
never.
BuildException:
if anything went wrong.
createArgumentback to summary
public Commandline.Argument createArgument()

Create a new argument to the java program.

Returns:Commandline.Argument

an argument to be configured.

createBootclasspathback to summary
public Path createBootclasspath(Project p)

Create a boot classpath.

Parameters
p:Project

the project to use to create the path.

Returns:Path

a path to be configured.

Since
Ant 1.6
createClasspathback to summary
public Path createClasspath(Project p)

Create a classpath.

Parameters
p:Project

the project to use to create the path.

Returns:Path

a path to be configured.

createModuleClassPairback to summary
private static String createModuleClassPair(final String module, final String classname)

Creates JDK 9 main module command line argument.

Parameters
module:String

the module name.

classname:String

the classname or null.

Returns:String

the main module with optional classname command line argument.

Since
1.9.7
createModulepathback to summary
public Path createModulepath(Project p)

Create a modulepath.

Parameters
p:Project

the project to use to create the path.

Returns:Path

a path to be configured.

Since
1.9.7
createUpgrademodulepathback to summary
public Path createUpgrademodulepath(Project p)

Create an upgrademodulepath.

Parameters
p:Project

the project to use to create the path.

Returns:Path

a path to be configured.

Since
1.9.7
createVmArgumentback to summary
public Commandline.Argument createVmArgument()

Create a new JVM argument.

Returns:Commandline.Argument

an argument to be configured.

describeCommandback to summary
public String describeCommand()

Return a String that describes the command and arguments suitable for verbose output before a call to Runtime.exec(String[]).

Returns:String

the description string.

Since
Ant 1.5
describeJavaCommandback to summary
public 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:String

the description string.

Since
Ant 1.5
getActualVMCommandback to summary
protected Commandline getActualVMCommand()

Get the VM command parameters, including memory settings.

Returns:Commandline

the VM command parameters.

getAssertionsback to summary
public Assertions getAssertions()

Get the current assertions.

Returns:Assertions

assertions or null.

getBootclasspathback to summary
public Path getBootclasspath()

Get the boot classpath.

Returns:Path

boot classpath or null.

getClassnameback to summary
public String getClassname()

Get the name of the class to be run.

Returns:String

the name of the class to run or null if there is no class.

See Also
getJar()
getClasspathback to summary
public Path getClasspath()

Get the classpath for the command.

Returns:Path

the classpath or null.

getCommandlineback to summary
public String[] getCommandline()

Get the command line to run a Java vm.

Returns:String[]

the list of all arguments necessary to run the vm.

getJarback to summary
public String getJar()

Get the name of the jar to be run.

Returns:String

the pathname of the jar file to run via -jar option or null if there is no jar to run.

See Also
getClassname()
getJavaCommandback to summary
public Commandline getJavaCommand()

Get the Java command to be used.

Returns:Commandline

the java command--not a clone.

getModuleback to summary
public String getModule()

Get the name of the module to be run.

Returns:String

the name of the module to run or null if there is no module.

Since
1.9.7
See Also
getJar(), getClassname()
getModulepathback to summary
public Path getModulepath()

Get the modulepath.

Returns:Path

modulepath or null.

Since
1.9.7
getSourceFileback to summary
public String getSourceFile()
Returns:String

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
getSystemPropertiesback to summary
public CommandlineJava.SysProperties getSystemProperties()

Get the system properties object.

Returns:CommandlineJava.SysProperties

The system properties object.

getUpgrademodulepathback to summary
public Path getUpgrademodulepath()

Get the upgrademodulepath.

Returns:Path

upgrademodulepath or null.

Since
1.9.7
getVmCommandback to summary
public Commandline getVmCommand()

Get the VM command, including memory.

Returns:Commandline

A deep clone of the instance's VM command, with memory settings added.

getVmversionback to summary
public String getVmversion()

Get the vm version.

Returns:String

the vm version.

haveBootclasspathback to summary
protected 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:boolean

whether to log a warning if a bootclasspath has been specified but will be ignored.

Returns:boolean

true if the bootclasspath is to be used.

Since
Ant 1.6
haveClasspathback to summary
public boolean haveClasspath()

Determine whether the classpath has been specified, and whether it shall really be used or be nulled by build.sysclasspath.

Returns:boolean

true if the classpath is to be used.

Since
Ant 1.6
haveModulepathback to summary
public boolean haveModulepath()

Determine whether the modulepath has been specified.

Returns:boolean

true if the modulepath is to be used.

Since
1.9.7
haveUpgrademodulepathback to summary
public boolean haveUpgrademodulepath()

Determine whether the upgrademodulepath has been specified.

Returns:boolean

true if the upgrademodulepath is to be used.

Since
1.9.7
isCloneVmback to summary
private boolean isCloneVm()

Find out whether either of the cloneVm attribute or the magic property ant.build.clonevm has been set.

Returns:boolean

boolean.

Since
1.7
parseClassFromModuleClassPairback to summary
private static String parseClassFromModuleClassPair(final String moduleClassPair)

Parses a classname from JDK 9 main module command line argument.

Parameters
moduleClassPair:String

a module with optional classname or null.

Returns:String

the classname or null.

Since
1.9.7
parseModuleFromModuleClassPairback to summary
private static String parseModuleFromModuleClassPair(final String moduleClassPair)

Parses a module name from JDK 9 main module command line argument.

Parameters
moduleClassPair:String

a module with optional classname or null.

Returns:String

the module name or null.

Since
1.9.7
restoreSystemPropertiesback to summary
public void restoreSystemProperties() throws BuildException

Restore the cached system properties.

Exceptions
BuildException:
if Security prevented this operation, or there was no system properties to restore
setAssertionsback to summary
public void setAssertions(Assertions assertions)

Add an assertion set to the command.

Parameters
assertions:Assertions

assertions to make.

setClassnameback to summary
public void setClassname(String classname)

Set the classname to execute.

Parameters
classname:String

the fully qualified classname.

setCloneVmback to summary
public 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:boolean

if true copy the system properties.

Since
Ant 1.7
setJarback to summary
public void setJar(String jarpathname)

Set a jar file to execute via the -jar option.

Parameters
jarpathname:String

the pathname of the jar to execute.

setMaxmemoryback to summary
public void setMaxmemory(String max)

Specify max memory of the JVM. -mx or -Xmx depending on VM version.

Parameters
max:String

the string to pass to the jvm to specify the max memory.

setModuleback to summary
public void setModule(final String module)

Set the module to execute.

Parameters
module:String

the module name.

Since
1.9.7
setSourceFileback to summary
public void setSourceFile(final String sourceFile)

Set the source-file, to execute as single file source programs, a feature, available since Java 11.

Parameters
sourceFile:String

The path to the source file

Since
Ant 1.10.5
setSystemPropertiesback to summary
public void setSystemProperties() throws BuildException

Cache current system properties and set them to those in this Java command.

Exceptions
BuildException:
if Security prevented this operation.
setVmback to summary
public void setVm(String vm)

Set the executable used to start the new JVM.

Parameters
vm:String

the executable to use.

setVmversionback to summary
public void setVmversion(String value)

Set the JVM version required.

Parameters
value:String

the version required.

sizeback to summary
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:int

the total number of arguments in the java command line.

Annotations
@Deprecated
See Also
getCommandline()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Get a string description.

Returns:String

the command line as a string.

Annotations
@Override
org.apache.tools.ant.types back to summary

private final Enum CommandlineJava.ExecutableType

extends Enum<CommandlineJava.ExecutableType>
Class Inheritance

Type of execution.
Since
1.9.7

Field Summary

Modifier and TypeField and Description
public static final CommandlineJava.ExecutableType
CLASS

Main class execution.

public static final CommandlineJava.ExecutableType
JAR

Jar file execution.

public static final CommandlineJava.ExecutableType
MODULE

Module execution.

public static final CommandlineJava.ExecutableType
SOURCE_FILE

Source file (introduced in Java 11)

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static CommandlineJava.ExecutableType
public static CommandlineJava.ExecutableType[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

CLASSback to summary
public static final CommandlineJava.ExecutableType CLASS

Main class execution.

JARback to summary
public static final CommandlineJava.ExecutableType JAR

Jar file execution.

MODULEback to summary
public static final CommandlineJava.ExecutableType MODULE

Module execution.

SOURCE_FILEback to summary
public static final CommandlineJava.ExecutableType SOURCE_FILE

Source file (introduced in Java 11)

Constructor Detail

ExecutableTypeback to summary
private ExecutableType()

Method Detail

valueOfback to summary
public static CommandlineJava.ExecutableType valueOf(String name)
valuesback to summary
public static CommandlineJava.ExecutableType[] values()
org.apache.tools.ant.types back to summary

public Class CommandlineJava.SysProperties

extends Environment
implements Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable

Specialized Environment class for System properties.

Field Summary

Modifier and TypeField and Description
private Vector<PropertySet>
pack-priv Properties
sys

the system properties.

Inherited from org.apache.tools.ant.types.Environment:
variables

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addDefinitionsToList(ListIterator<String>
list iterator supporting add method.
listIt
)

Add all definitions (including property sets) to a list.

public void
addSysproperties(CommandlineJava.SysProperties
the new property set.
ps
)

Add a propertyset to the total set.

public void
addSyspropertyset(PropertySet
the new property set.
ps
)

Add a propertyset to the total set.

public Object

Returns:

a cloned instance of SysProperties.
clone
()

Overrides java.lang.Object.clone.

Create a deep clone.
public String[]

Returns:

the array of definitions; may be null.
getVariables
()

Overrides org.apache.tools.ant.types.Environment.getVariables.

Get the properties as an array; this is an override of the superclass, as it evaluates all the properties.
private Properties

Returns:

the merged object.
mergePropertySets
()

Merge all property sets into a single Properties object.

public void
restoreSystem()

Restore the system properties to the cached value.

public void
setSystem()

Cache the system properties and set the system properties to the new values.

public int

Returns:

the size of the sysproperties instance.
size
()

Get the size of the sysproperties instance.

Inherited from org.apache.tools.ant.types.Environment:
addVariablegetVariablesVector

Field Detail

propertySetsback to summary
private Vector<PropertySet> propertySets
sysback to summary
pack-priv Properties sys

the system properties.

Constructor Detail

SysPropertiesback to summary
public SysProperties()

Method Detail

addDefinitionsToListback to summary
public void addDefinitionsToList(ListIterator<String> listIt)

Add all definitions (including property sets) to a list.

Parameters
listIt:ListIterator<String>

list iterator supporting add method.

addSyspropertiesback to summary
public void addSysproperties(CommandlineJava.SysProperties ps)

Add a propertyset to the total set.

Parameters
ps:CommandlineJava.SysProperties

the new property set.

Since
Ant 1.6.3
addSyspropertysetback to summary
public void addSyspropertyset(PropertySet ps)

Add a propertyset to the total set.

Parameters
ps:PropertySet

the new property set.

cloneback to summary
public Object clone() throws CloneNotSupportedException

Overrides java.lang.Object.clone.

Create a deep clone.

Returns:Object

a cloned instance of SysProperties.

Annotations
@SuppressWarnings:unchecked
@Override
Exceptions
CloneNotSupportedException:
for signature.
getVariablesback to summary
public String[] getVariables() throws BuildException

Overrides org.apache.tools.ant.types.Environment.getVariables.

Get the properties as an array; this is an override of the superclass, as it evaluates all the properties.

Returns:String[]

the array of definitions; may be null.

Annotations
@Override
Exceptions
BuildException:
on error.
mergePropertySetsback to summary
private Properties mergePropertySets()

Merge all property sets into a single Properties object.

Returns:Properties

the merged object.

restoreSystemback to summary
public void restoreSystem() throws BuildException

Restore the system properties to the cached value.

Exceptions
BuildException:
if Security prevented this operation, or there were no system properties to restore.
setSystemback to summary
public void setSystem() throws BuildException

Cache the system properties and set the system properties to the new values.

Exceptions
BuildException:
if Security prevented this operation.
sizeback to summary
public int size()

Get the size of the sysproperties instance. This merges all property sets, so is not an O(1) operation.

Returns:int

the size of the sysproperties instance.