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 mode
      void 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 be null.
      • setJvm

        void setJvm​(String command)
        Sets the command to launch the JVM.
        Parameters:
        command - The command to lauch the JVM, may be null.
      • addJvmArgument

        void addJvmArgument​(File file)
        Adds the specified pathname as an argument to the JVM.
        Parameters:
        file - The pathname to add, may be null.
      • addJvmArguments

        void addJvmArguments​(String... values)
        Adds the specified values as arguments to the JVM.
        Parameters:
        values - The values to add, may be null.
      • 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 be null.
      • addClasspathEntries

        void addClasspathEntries​(String... paths)
        Adds the specified paths to the system classpath of the JVM.
        Parameters:
        paths - The classpath entries, may be null.
      • addClasspathEntries

        void addClasspathEntries​(File... paths)
        Adds the specified paths to the system classpath of the JVM.
        Parameters:
        paths - The classpath entries, may be null.
      • 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 be null.
        value - The property value, may be null.
      • setEnvironmentVariable

        void setEnvironmentVariable​(String name,
                                    String value)
        Sets an environment variable for the JVM.
        Parameters:
        name - The variable name, may be null.
        value - The property value, may be null.
      • 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 using System.getenv(java.lang.String).
        Parameters:
        name - The variable name, may be null.
        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 of setJarFile(File) and setMainClass(String) may be invoked.
        Parameters:
        jarFile - The JAR file to execute, may be null.
      • setMainClass

        void setMainClass​(String mainClass)
        Sets the qualified name of the Java class to execute. Only one of setJarFile(File) and setMainClass(String) may be invoked.
        Parameters:
        mainClass - The qualified name of the Java class to execute, may be null.
      • addAppArgument

        void addAppArgument​(File file)
        Adds the specified pathname as an argument to the application.
        Parameters:
        file - The pathname to add, may be null.
      • addAppArguments

        void addAppArguments​(String... values)
        Adds the specified values as arguments to the application.
        Parameters:
        values - The values to add, may be null.
      • addAppArgumentLine

        void addAppArgumentLine​(String line)
        Adds the specified comma separated argument line as arguments to the application.
        Parameters:
        line - The arguments to add, may be null.
      • 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 be null.
      • 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 be null.
        category - the log category to use when logging the JVM's outputs, should not be null.
      • 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.