org.apache.commons.launcher

Class LaunchTask


public class LaunchTask
extends Task

A class that eliminates the need for a batch or shell script to launch a Java class. Some situations where elimination of a batch or shell script may be desirable are:

Author:
Patrick Luby

Field Summary

static String
ARG_PROP_NAME
The argument property name.
static String
TASK_NAME
The name of this task.

Method Summary

void
addArg(ConditionalArgument arg)
Add a nested arg element.
void
addArgset(ArgumentSet set)
Add a nested argset element.
void
addJvmarg(ConditionalArgument jvmArg)
Add a nested jvmarg element.
void
addJvmargset(JVMArgumentSet set)
Add a nested jvmargset element.
void
addSysproperty(ConditionalVariable var)
Add a nested sysproperty element.
void
addSyspropertyset(SysPropertySet set)
Add a nested syspropertyset element.
Path
createClasspath()
Create a nested classpath element.
Path
createFilterclasspath()
Create a nested filter classpath element.
void
execute()
Construct a Java command and execute it using the settings that Ant parsed from the Launcher's XML file.
static Process[]
getChildProcesses()
Get the synchronous child processes for all instances of this class.
void
setAppendoutput(boolean appendOutput)
Set the appendOutput flag.
void
setClassname(String mainClassName)
Set the class name.
void
setClasspath(Path classpath)
Set the classpath.
void
setClasspathref(Reference ref)
Adds a reference to a classpath defined elsewhere.
void
setDebug(boolean debug)
Set the debug flag.
void
setDisplayminimizedwindow(boolean displayMinimizedWindow)
Set the displayMinimizedWindow flag.
void
setDisposeminimizedwindow(boolean disposeMinimizedWindow)
Set the disposeMinimizedWindow flag.
void
setFailonerror(boolean failOnError)
Set the failOnError flag.
void
setFilterclassname(String filterClassName)
Set the filter class name.
void
setFilterclasspath(Path filterClasspath)
Set the filter class' classpath.
void
setMinimizedwindowicon(File minimizedWindowIcon)
Set the icon file for the minimized window that will be displayed in the Windows taskbar.
void
setMinimizedwindowtitle(String minimizedWindowTitle)
Set the title for the minimized window that will be displayed in the Windows taskbar.
void
setOutput(File outputFile)
Set the file that the child JVM's System.out and System.err will be redirected to.
void
setPrint(boolean print)
Set the print flag.
void
setRedirectoutput(boolean redirect)
Set the redirect flag.
void
setRequiretools(boolean requireTools)
Set the requireTools flag.
void
setUseargs(boolean useArgs)
Set the useArgs flag.
void
setUsesystemin(boolean useSystemIn)
Set the useSystemIn flag.
void
setWaitforchild(boolean waitForChild)
Set the waitForChild flag.

Field Details

ARG_PROP_NAME

public static final String ARG_PROP_NAME
The argument property name.


TASK_NAME

public static final String TASK_NAME
The name of this task.

Method Details

addArg

public void addArg(ConditionalArgument arg)
Add a nested arg element. Note that Ant will not invoke the specified arg object's setter methods until after Ant invokes this method so processing of the specified arg object is handled in the execute() method.

Parameters:
arg - the arg element


addArgset

public void addArgset(ArgumentSet set)
Add a nested argset element.

Parameters:
set - the argset element


addJvmarg

public void addJvmarg(ConditionalArgument jvmArg)
Add a nested jvmarg element. Note that Ant will not invoke the specified jvmarg object's setter methods until after Ant invokes this method so processing of the specified jvmarg object is handled in the execute() method.

Parameters:
jvmArg - the jvmarg element


addJvmargset

public void addJvmargset(JVMArgumentSet set)
Add a nested jvmargset element.

Parameters:
set - the jvmargset element


addSysproperty

public void addSysproperty(ConditionalVariable var)
Add a nested sysproperty element. Note that Ant will not invoke the specified sysproperty object's setter methods until after Ant invokes this method so processing of the specified sysproperty object is handled in the execute() method.

Parameters:
var - the sysproperty element


addSyspropertyset

public void addSyspropertyset(SysPropertySet set)
Add a nested syspropertyset element.

Parameters:
set - the syspropertyset element


createClasspath

public Path createClasspath()
Create a nested classpath element.

Returns:
the Path object that contains all nested classpath elements


createFilterclasspath

public Path createFilterclasspath()
Create a nested filter classpath element.

Returns:
the Path object that contains all nested filter classpath elements


execute

public void execute()
            throws BuildException
Construct a Java command and execute it using the settings that Ant parsed from the Launcher's XML file. This method is called by the Ant classes.


getChildProcesses

public static Process[] getChildProcesses()
Get the synchronous child processes for all instances of this class.

Returns:
the instances of this class.


setAppendoutput

public void setAppendoutput(boolean appendOutput)

Parameters:
appendOutput - true if output should be appended to the output file


setClassname

public void setClassname(String mainClassName)
Set the class name.

Parameters:
mainClassName - the class to execute main(String[])


setClasspath

public void setClasspath(Path classpath)
Set the classpath.

Parameters:
classpath - the classpath


setClasspathref

public void setClasspathref(Reference ref)
Adds a reference to a classpath defined elsewhere.

Parameters:
ref - reference to the classpath


setDebug

public void setDebug(boolean debug)
Set the debug flag. Setting this flag to true will cause this task to run the child JVM using the JDB debugger.

Parameters:
debug - the debug flag


setDisplayminimizedwindow

public void setDisplayminimizedwindow(boolean displayMinimizedWindow)

Parameters:
displayMinimizedWindow - true if a minimized window should be displayed in the Windows task bar while the child process is executing


setDisposeminimizedwindow

public void setDisposeminimizedwindow(boolean disposeMinimizedWindow)
Set the disposeMinimizedWindow flag. Note that this flag has no effect on non-Windows platforms. On Windows platform, setting this flag to true will cause any minimized window that is display by setting the "displayMinimizedWindow" attribute to true via the setDisplayminimizedwindow(boolean) to be automatically disposed of when the child JVM's main(String[]) returns. This flag is normally used for applications that don't explicitly call System.exit(int). If an application does not explicitly call System.exit(int), an minimized windows need to be disposed of for the child JVM to exit.

Parameters:
disposeMinimizedWindow - true if a minimized window in the Windows taskbar should be automatically disposed of after the child JVM's main(String[]) returns


setFailonerror

public void setFailonerror(boolean failOnError)
Set the failOnError flag.

Parameters:
failOnError - true if the launch process should stop if the child JVM returns an exit value other than 0


setFilterclassname

public void setFilterclassname(String filterClassName)

Parameters:
filterClassName - the class that implements the


setFilterclasspath

public void setFilterclasspath(Path filterClasspath)
Set the filter class' classpath.

Parameters:


setMinimizedwindowicon

public void setMinimizedwindowicon(File minimizedWindowIcon)
Set the icon file for the minimized window that will be displayed in the Windows taskbar. Note that this property has no effect on non-Windows platforms.

Parameters:
minimizedWindowIcon - the icon file to use for any minimized window that is displayed in the Windows taskbar


setMinimizedwindowtitle

public void setMinimizedwindowtitle(String minimizedWindowTitle)
Set the title for the minimized window that will be displayed in the Windows taskbar. Note that this property has no effect on non-Windows platforms.

Parameters:
minimizedWindowTitle - the title to set for any minimized window that is displayed in the Windows taskbar


setOutput

public void setOutput(File outputFile)

Parameters:
outputFile - a File to redirect System.out and System.err to


setPrint

public void setPrint(boolean print)
Set the print flag. Setting this flag to true will cause the full child JVM command to be printed to System.out.

Parameters:
print - the print flag


setRedirectoutput

public void setRedirectoutput(boolean redirect)

Parameters:
redirect - true if System.out and System.err should be redirected


setRequiretools

public void setRequiretools(boolean requireTools)
Set the requireTools flag. Setting this flag to true will cause the JVM's tools.jar to be added to the child JVM's classpath. This sets an explicit requirement that the user use a JDK instead of a JRE. Setting this flag to false explicitly allows the user to use a JRE.

Parameters:


setUseargs

public void setUseargs(boolean useArgs)

Parameters:
useArgs - the useArgs flag


setUsesystemin

public void setUsesystemin(boolean useSystemIn)
Set the useSystemIn flag. Setting this flag to false will cause this task to not read System.in. This will cause the child JVM to never receive any bytes when it reads System.in. Setting this flag to false is useful in some Unix environments where processes cannot be put in the background when they read System.in.

Parameters:
useSystemIn - the useSystemIn flag


setWaitforchild

public void setWaitforchild(boolean waitForChild)
Set the waitForChild flag. Setting this flag to true will cause this task to wait for the child JVM to finish executing before the task completes. Setting this flag to false will cause this task to complete immediately after it starts the execution of the child JVM. Setting it false emulates the "&" background operator in most Unix shells and is most of set to false when launching server or GUI applications.

Parameters:
waitForChild - the waitForChild flag


Copyright (c) 2001-2002 - Apache Software Foundation