Interface JvmLauncher
-
- All Known Implementing Classes:
DefaultJvmLauncher
public interface JvmLauncher
A JVM launcher is responsible to fork a JVM.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addAppArgument(File file)
Adds the specified pathname as an argument to the application.void
addAppArgumentLine(String line)
Adds the specified comma separated argument line as arguments to the application.void
addAppArguments(String... values)
Adds the specified values as arguments to the application.void
addClasspathEntries(File... paths)
Adds the specified paths to the system classpath of the JVM.void
addClasspathEntries(String... paths)
Adds the specified paths to the system classpath of the JVM.void
addJvmArgument(File file)
Adds the specified pathname as an argument to the JVM.void
addJvmArgumentLine(String line)
Adds the specified comma separated argument line as arguments to the JVM.void
addJvmArguments(String... values)
Adds the specified values as arguments to the JVM.int
execute()
Launches a JVM according to the configuration of this launcher and waits for its termination.String
getClasspath()
Gets the currently configured system classpath.String
getCommandLine()
Gets a string representation of the currently configured command line.String
getEnvironmentVariable(String name)
Gets an environment variable, as configured for the JVM.void
kill()
Forcibly kill the process that was launched, if supported by the JvmLauncher implementation.void
setAppendOutput(boolean appendOutput)
Controls whether the redirected output should be appended to an existing output file (if any).void
setEnvironmentVariable(String name, String value)
Sets an environment variable for the JVM.void
setJarFile(File jarFile)
Sets the JAR file containing the main class to execute.void
setJvm(String command)
Sets the command to launch the JVM.void
setMainClass(String mainClass)
Sets the qualified name of the Java class to execute.void
setOutputFile(File outputFile)
Sets the file to which the output of the JVM is redirected.void
setOutputLogger(Logger outputLogger, String category)
Sets the logger to which the output of the JVM is redirected.void
setSpawn(boolean spawn)
Sets whether the JVM should be launched in spawn modevoid
setSystemProperty(String name, String value)
Sets a system property for the JVM.void
setTimeout(long millis)
Sets the timeout in milliseconds after which the process will be killed if still running.void
setWorkingDirectory(File workingDirectory)
Sets the working directory for the forked JVM.void
start()
Launches a JVM according to the configuration of this launcher.
-
-
-
Method Detail
-
setWorkingDirectory
void setWorkingDirectory(File workingDirectory)
Sets the working directory for the forked JVM.- Parameters:
workingDirectory
- The working directory for the forked JVM, may benull
.
-
setJvm
void setJvm(String command)
Sets the command to launch the JVM.- Parameters:
command
- The command to lauch the JVM, may benull
.
-
addJvmArgument
void addJvmArgument(File file)
Adds the specified pathname as an argument to the JVM.- Parameters:
file
- The pathname to add, may benull
.
-
addJvmArguments
void addJvmArguments(String... values)
Adds the specified values as arguments to the JVM.- Parameters:
values
- The values to add, may benull
.
-
addJvmArgumentLine
void addJvmArgumentLine(String line)
Adds the specified comma separated argument line as arguments to the JVM.- Parameters:
line
- The arguments to add, may be benull
.
-
addClasspathEntries
void addClasspathEntries(String... paths)
Adds the specified paths to the system classpath of the JVM.- Parameters:
paths
- The classpath entries, may benull
.
-
addClasspathEntries
void addClasspathEntries(File... paths)
Adds the specified paths to the system classpath of the JVM.- Parameters:
paths
- The classpath entries, may benull
.
-
getClasspath
String getClasspath()
Gets the currently configured system classpath.- Returns:
- The currently configured system classpath, never
null
.
-
setSystemProperty
void setSystemProperty(String name, String value)
Sets a system property for the JVM.- Parameters:
name
- The property name, may benull
.value
- The property value, may benull
.
-
setEnvironmentVariable
void setEnvironmentVariable(String name, String value)
Sets an environment variable for the JVM.- Parameters:
name
- The variable name, may benull
.value
- The property value, may benull
.
-
getEnvironmentVariable
String getEnvironmentVariable(String name)
Gets an environment variable, as configured for the JVM. In case of manipulation of an existing variable, instead of replacing it (eg: when adding an additional directory to PATH) it is recommended to retrieve the value using this method instead of usingSystem.getenv(java.lang.String)
.- Parameters:
name
- The variable name, may benull
.- Returns:
- Either the previously set value, the system value or null.
-
setJarFile
void setJarFile(File jarFile)
Sets the JAR file containing the main class to execute. Only one ofsetJarFile(File)
andsetMainClass(String)
may be invoked.- Parameters:
jarFile
- The JAR file to execute, may benull
.
-
setMainClass
void setMainClass(String mainClass)
Sets the qualified name of the Java class to execute. Only one ofsetJarFile(File)
andsetMainClass(String)
may be invoked.- Parameters:
mainClass
- The qualified name of the Java class to execute, may benull
.
-
addAppArgument
void addAppArgument(File file)
Adds the specified pathname as an argument to the application.- Parameters:
file
- The pathname to add, may benull
.
-
addAppArguments
void addAppArguments(String... values)
Adds the specified values as arguments to the application.- Parameters:
values
- The values to add, may benull
.
-
addAppArgumentLine
void addAppArgumentLine(String line)
Adds the specified comma separated argument line as arguments to the application.- Parameters:
line
- The arguments to add, may benull
.
-
setOutputFile
void setOutputFile(File outputFile)
Sets the file to which the output of the JVM is redirected.- Parameters:
outputFile
- The file to which the output of the JVM is redirected, may benull
.
-
setAppendOutput
void setAppendOutput(boolean appendOutput)
Controls whether the redirected output should be appended to an existing output file (if any).- Parameters:
appendOutput
-true
to append the output,false
to overwrite the file.- See Also:
setOutputFile(File)
-
setOutputLogger
void setOutputLogger(Logger outputLogger, String category)
Sets the logger to which the output of the JVM is redirected.- Parameters:
outputLogger
- The logger to which the output of the JVM is redirected, may benull
.category
- the log category to use when logging the JVM's outputs, should not benull
.
-
getCommandLine
String getCommandLine()
Gets a string representation of the currently configured command line.- Returns:
- The currently configured command line, never
null
.
-
kill
void kill()
Forcibly kill the process that was launched, if supported by the JvmLauncher implementation.
-
setTimeout
void setTimeout(long millis)
Sets the timeout in milliseconds after which the process will be killed if still running.- Parameters:
millis
- The timeout, may be non-positive to disable process watching.
-
setSpawn
void setSpawn(boolean spawn)
Sets whether the JVM should be launched in spawn mode- Parameters:
spawn
-true
to launch JVM in spawn,false
to launch normal JVM.
-
start
void start() throws JvmLauncherException
Launches a JVM according to the configuration of this launcher. The method returns as soon as the JVM got launched and does not wait for its termination.- Throws:
JvmLauncherException
- If the JVM could not be launched.
-
execute
int execute() throws JvmLauncherException
Launches a JVM according to the configuration of this launcher and waits for its termination.- Returns:
- The exit code of the JVM.
- Throws:
JvmLauncherException
- If the JVM could not be launched.
-
-