JTools

net.jtools.ant
Class JavaLauncher

java.lang.Object
  extended by org.apache.tools.ant.ProjectComponent
      extended by org.apache.tools.ant.Task
          extended by net.jtools.ant.JavaLauncher
Direct Known Subclasses:
TmplModelTask

public class JavaLauncher
extends Task

Launcher for Java applications. Allows use of the same JVM for the called application thus resulting in much faster operation.

Since:
Ant 1.1
Author:
Stefano Mazzocchi stefano@apache.org , Stefan Bodewig

Field Summary
protected  boolean append
           
protected  CommandlineJava cmdl
           
protected  File dir
           
protected  Environment env
           
protected  boolean failOnError
           
protected  boolean fork
           
protected  boolean newEnvironment
           
protected  File out
           
protected  PrintStream outStream
           
protected  Long timeout
           
 
Fields inherited from class org.apache.tools.ant.Task
description, location, target, taskName, taskType, wrapper
 
Fields inherited from class org.apache.tools.ant.ProjectComponent
project
 
Constructor Summary
JavaLauncher()
           
 
Method Summary
 void addEnv(Environment.Variable var)
          Adds an environment variable.
 void addSysproperty(Environment.Variable sysp)
          Adds a system property.
 void clearArgs()
          Clear out the arguments to this java task.
 Commandline.Argument createArg()
          Adds a command-line argument.
 Path createClasspath()
          Adds a path to the classpath.
 Commandline.Argument createJvmarg()
          Adds a JVM argument.
protected  ExecuteWatchdog createWatchdog()
          Create the Watchdog to kill a runaway process.
 void execute()
           
 void executeDirect()
          Do the execution.
 void executeForked()
           
 int executeJava()
          Do the execution and return a return code.
 void executeMain()
           
protected  void handleErrorFlush(String line)
          Pass output sent to System.err to specified output file.
protected  void handleErrorOutput(String line)
          Pass output sent to System.err to specified output file.
protected  void handleFlush(String line)
          Pass output sent to System.out to specified output file.
protected  void handleOutput(String line)
          Pass output sent to System.out to specified output file.
protected  void run(String classname, Vector args)
          Executes the given classname with the given arguments as it was a command line application.
 void setAppend(boolean append)
          If true, append output to existing file.
 void setArgs(String s)
          Deprecated: use nested arg instead.
 void setClassname(String s)
          Sets the Java class to execute.
 void setClasspath(Path s)
          Set the classpath to be used when running the Java class
 void setClasspathRef(Reference r)
          Classpath to use, by reference.
 void setDir(File d)
          The working directory of the process
 void setFailonerror(boolean fail)
          If true, then fail if the command exits with a returncode other than 0
 void setFork(boolean s)
          If true, execute in a new VM.
 void setJar(File jarfile)
          The location of the JAR file to execute.
 void setJvm(String s)
          Set the command used to start the VM (only if not forking).
 void setJvmargs(String s)
          Set the command line arguments for the JVM.
 void setJVMVersion(String value)
          Sets the JVM version.
 void setMaxmemory(String max)
          Corresponds to -mx or -Xmx depending on VM version.
 void setNewenvironment(boolean newenv)
          If true, use a completely new environment.
 void setOutput(File out)
          File the output of the process is redirected to.
 void setTimeout(Long value)
          Timeout in milliseconds after which the process will be killed.
 
Methods inherited from class org.apache.tools.ant.Task
getDescription, getLocation, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleInput, init, isInvalid, log, log, maybeConfigure, perform, reconfigure, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
 
Methods inherited from class org.apache.tools.ant.ProjectComponent
getProject, setProject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

append

protected boolean append

cmdl

protected CommandlineJava cmdl

dir

protected File dir

env

protected Environment env

failOnError

protected boolean failOnError

fork

protected boolean fork

newEnvironment

protected boolean newEnvironment

out

protected File out

outStream

protected PrintStream outStream

timeout

protected Long timeout
Constructor Detail

JavaLauncher

public JavaLauncher()
Method Detail

addEnv

public void addEnv(Environment.Variable var)
Adds an environment variable.

Will be ignored if we are not forking a new VM.

Since:
Ant 1.5

addSysproperty

public void addSysproperty(Environment.Variable sysp)
Adds a system property.


clearArgs

public void clearArgs()
Clear out the arguments to this java task.


createArg

public Commandline.Argument createArg()
Adds a command-line argument.


createClasspath

public Path createClasspath()
Adds a path to the classpath.


createJvmarg

public Commandline.Argument createJvmarg()
Adds a JVM argument.


createWatchdog

protected ExecuteWatchdog createWatchdog()
                                  throws BuildException
Create the Watchdog to kill a runaway process.

Throws:
BuildException
Since:
Ant 1.5

execute

public void execute()
             throws BuildException
Overrides:
execute in class Task
Throws:
BuildException

executeDirect

public void executeDirect()
                   throws BuildException
Do the execution.

Throws:
BuildException

executeForked

public void executeForked()
                   throws BuildException
Throws:
BuildException

executeJava

public int executeJava()
                throws BuildException
Do 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").
Throws:
BuildException

executeMain

public void executeMain()
                 throws BuildException
Throws:
BuildException

handleErrorFlush

protected void handleErrorFlush(String line)
Pass output sent to System.err to specified output file.

Overrides:
handleErrorFlush in class Task
Since:
Ant 1.5.2

handleErrorOutput

protected void handleErrorOutput(String line)
Pass output sent to System.err to specified output file.

Overrides:
handleErrorOutput in class Task
Since:
Ant 1.5

handleFlush

protected void handleFlush(String line)
Pass output sent to System.out to specified output file.

Overrides:
handleFlush in class Task
Since:
Ant 1.5.2

handleOutput

protected void handleOutput(String line)
Pass output sent to System.out to specified output file.

Overrides:
handleOutput in class Task
Since:
Ant 1.5

run

protected void run(String classname,
                   Vector args)
            throws BuildException
Executes the given classname with the given arguments as it was a command line application.

Throws:
BuildException

setAppend

public void setAppend(boolean append)
If true, append output to existing file.

Since:
Ant 1.5

setArgs

public void setArgs(String s)
Deprecated: use nested arg instead. Set the command line arguments for the class.


setClassname

public void setClassname(String s)
                  throws BuildException
Sets the Java class to execute.

Throws:
BuildException

setClasspath

public void setClasspath(Path s)
Set the classpath to be used when running the Java class

Parameters:
s - an Ant Path object containing the classpath.

setClasspathRef

public void setClasspathRef(Reference r)
Classpath to use, by reference.


setDir

public void setDir(File d)
The working directory of the process


setFailonerror

public void setFailonerror(boolean fail)
If true, then fail if the command exits with a returncode other than 0


setFork

public void setFork(boolean s)
If true, execute in a new VM.


setJar

public void setJar(File jarfile)
            throws BuildException
The location of the JAR file to execute.

Throws:
BuildException

setJvm

public void setJvm(String s)
Set the command used to start the VM (only if not forking).


setJvmargs

public void setJvmargs(String s)
Set the command line arguments for the JVM.


setJVMVersion

public void setJVMVersion(String value)
Sets the JVM version.

Parameters:
value - JVM version

setMaxmemory

public void setMaxmemory(String max)
Corresponds to -mx or -Xmx depending on VM version.


setNewenvironment

public void setNewenvironment(boolean newenv)
If true, use a completely new environment.

Will be ignored if we are not forking a new VM.

Since:
Ant 1.5

setOutput

public void setOutput(File out)
File the output of the process is redirected to.


setTimeout

public void setTimeout(Long value)
Timeout in milliseconds after which the process will be killed.

Since:
Ant 1.5

JTools

© 2000-2006, JTools.org.