JavaTF

Run a Java class or a Jar.

Task package:org.schmant.task.base
Java package:org.schmant.task.jdk.java
Category:Execution tasks
Since:0.5
EntityFS-aware?No*

Description:

Run a Java class or a Jar in a separate process. The task does not return until the external JVM has terminated.

The following strategy is used for searching for the java command to use:

  1. Use a Java executable suggested by an ExtJavaTaskDecorator, if any
  2. Use the javaExecutable property, if set
  3. Use the file bin/java[.exe] relative to the javaHome property, if set
  4. Use the file bin/java[.exe] relative to the JAVA_HOME environment variable, if set
  5. Search for java[.exe] in the paths listed in the PATH environment variable

Required properties

Properties

argumentstop

Arguments to the program. The arguments will be given to the program in the order that they are added.

Setter method:
addArgument(String arg)
Add one program argument.
parameters:
arg – The program argument, for instance -f out.txt.
Setter method:
addArguments(Object o)
Add one program argument or an array or a collection of program arguments.
parameters:
o – One program argument or an array or collection of program arguments (strings).
Setter method:
clearArguments()
Clear the list of program arguments.
assertionstop

Should Java assertions be enabled? More fine-grained assertion settings can be set by setting JVM options.

Setter method:
setAssertions(boolean b)
parameters:
b – Should assertions be enabled?
Default value:
false (assertions are not enabled).
See also:
jvmOptions
classpathDecoratorstop

A collection of PathDecorator:s that are used to add entries to the classpath. The decorators are run in the order that they are added to this property. Classpath decorator entries are added to the classpath after all entries added manually to the classpathEntries property.

Setter method:
addClasspathDecorator(PathDecorator pd)
Add one classpath decorator to the end of the list.
parameters:
pd – A classpath decorator.
Setter method:
addClasspathDecorators(Object o)
Add one or several classpath decorators.
parameters:
o – One or an array or collection of classpath decorators (PathDecorator objects).
Setter method:
clearClasspathDecorators()
Clear the list of classpath decorators.
See also:
classpathEntries
classpathEntriestop

Manually set classpath entries. An entry must be a Jar file or a class file directory.

Setter method:
addClasspathEntries(Object o)
Add one or several classpath entries.
parameters:
o – One or an array or collection of entries to add to the class path.
Interpreted by InterpretAsFileStrategy.
Setter method:
addClasspathEntry(Object o)
Add one entry to the end of the class path.
parameters:
o – The entry to add to the class path.
Interpreted by InterpretAsFileStrategy.
Setter method:
clearClasspathEntries()
Clear the list of classpath entries.
See also:
classpathDecorators
classToRun (semi-required) top

The fully qualified name of a Java class to run.

Setter method:
setClassToRun(String s)
parameters:
s – The class to run.
See also:
jarToRun
decoratorstop

A list of ExtJavaTaskDecorator:s. Decorators are used to configure the program to run.

Setter method:
addDecorator(ExtJavaTaskDecorator d)
Add a decorator to the end of the list.
parameters:
d – A Java task decorator
Setter method:
addDecorators(Object o)
Add one or several Java task decorators.
parameters:
o – One Java task decorator or an array or collection of Java task decorators (ExtJavaTaskDecorator objects).
Setter method:
clearDecorators()
Clear the list of decorators.
environmentVariablestop

Environment variables for the program. By default, the variables set are added to the environment of the Schmant script. See the inheritEnvironmentVariables property.

Setter method:
addEnvironmentVariable(String name, String value)
parameters:
name – The environment variable name, for instance PATH.
value – The value of the variable.
Setter method:
addEnvironmentVariables(Object o)
Add one or several environment variables.
parameters:
o – A string or an array or collection of strings. Each string must have the format NAME=VALUE.
Setter method:
clearEnvironmentVariables()
Clear the collection of environment variables.
See also:
inheritEnvironmentVariables
failOnErrorstop

If the program exits with an error (an exit code != 0), should the task fail? See also ErrorIgnoringTF.

Setter method:
setFailOnErrors(boolean b)
parameters:
b – Should the task fail on errors?
Default value:
true (fails on errors)
inheritEnvironmentVariablestop

Should the environment variables of the Schmant script be inherited?

Setter method:
setInheritEnvironmentVariables(boolean b)
parameters:
b – Should environment variables be inherited?
Default value:
true (environment variables are inherited)
See also:
environmentVariables
jarToRun (semi-required) top

A Jar file to run.

Setter method:
setJarToRun(Object o)
parameters:
o – The Jar file to run.
Interpreted by InterpretAsFileStrategy.
See also:
classToRun
javaExecutabletop

The path to the java[.exe] command. Decorators may also set the Java executable to use. In that case, that setting take precedence.

Setter method:
setJavaExecutable(Object o)
parameters:
o – The path to the java[.exe] command.
Interpreted by InterpretAsFileStrategy.
Default value:
The Java executable to use is, in this order of precedence:
  1. A Java executable set by any of the decorators.
  2. This property.
  3. A Java executable found in the catalog referenced by the javaHome property, if set.
  4. A Java executable found in the catalog referenced by the JAVA_HOME environment variable, if set.
  5. A Java executable found in the directories referenced by the PATH environment variable.
See also:
javaHome
javaHometop

The location of the Java Runtime Environment or Java Development Kit to use

Setter method:
setJavaHome(Object o)
parameters:
o – The path to a JRE or JDK.
Interpreted by InterpretAsFileDirectoryStrategy.
See also:
javaExecutable
javaVMTypetop

The Java virtual machine type to use (client or server).

Setter method:
setJavaVMType(JavaVMType t)
parameters:
t – The virtual machine type:
  • JavaVMType.CLIENT
  • JavaVMType.SERVER

Default value:
The JVM:s default virtual machine type, probably client.
jvmOptionstop

Options for the java command. Options are arguments to java given before the class to run, see the JDK documentation on java.

Setter method:
addJvmOption(String s)
parameters:
s – Add an option
Setter method:
addJvmOptions(Object o)
parameters:
o – One JVM option or an array or collection of JVM options (strings).
Setter method:
clearJvmOptions()
Clear the list of JVM options.
logFootertop

The message that is logged to info level after the task has been successfully run.

Setter method:
setLogFooter(String s)
parameters:
s – The footer message.
Default value:
Empty (no footer message is logged.)
See also:
logHeader
logHeadertop

The message that is logged to info level before the task is run.

Setter method:
setLogHeader(String s)
parameters:
s – The header message.
Default value:
A task class specific message.
See also:
logFooter
reportLeveltop

This property is used to change the Report level for all task created by this task factory. The report level is changed for the thread running the task when the it is run, and is restored to its previous level when the it is done.

Setter method:
setReportLevel(Level l)
Set the report level
parameters:
l – The new report level.
stderrStrategytop

A ProcessOutputStrategy for handling the program's output to stderr.

Setter method:
setStderrStrategy(ProcessOutputStrategy s)
parameters:
s – The stderr strategy.
Default value:
A LoggingProcessOutputStrategy that logs output to the Level.SEVERE
See also:
stdoutStrategy
stdoutStrategytop

A ProcessOutputStrategy for handling the program's output to stdout.

Setter method:
setStdoutStrategy(ProcessOutputStrategy s)
parameters:
s – The stdout strategy.
Default value:
A LoggingProcessOutputStrategy that logs output to the Level.INFO
See also:
stderrStrategy
traceLoggingtop

If trace logging is enabled for a task, it reports its configuration before it is run.

Trace logging may also be enabled globally for all tasks by calling TraceMode.setTraceMode(boolean).

Setter method:
setTraceLogging(boolean b)
Enable or disable trace logging.
parameters:
b – Enable trace logging?
workingDirectorytop

The working directory for the program. (The directory that the program is started in.)

Setter method:
setWorkingDirectory(Object o)
parameters:
o – A directory.
Interpreted by InterpretAsFileDirectoryStrategy.
Default value:
The Schmant process' working directory. The Schmant launcher scripts sets this to the directory where the current script file is.

Examples


* That a task is not EntityFS-aware means that it is not aware of DirectoryView filters (it uses them as plain Directory:s) and also that it usually requires that the entities it takes as arguments are in a File-based file file system. (That they are ECFileResolvable.) A non File-resolvable entity can be made so by using the SchmantFileSystems.makeFileResolvable(org.entityfs.EFile) method.