java.lang.Object
org.matwoess.jsourceprofiler.common.JavaCommandBuilder

public class JavaCommandBuilder extends Object
Builder class for a java command line with arguments. Used as a common abstraction to avoid hard-coding an array of java command strings for ProcessBuilder usages.
  • Constructor Details

    • JavaCommandBuilder

      public JavaCommandBuilder()
  • Method Details

    • setMainClass

      public JavaCommandBuilder setMainClass(String mainClass)
      Register the main class name, later added as the first argument after options.
      Parameters:
      mainClass - the qualified name of the compiled class containing the main entry point
      Returns:
      the builder object itself for method chaining
    • setClassPath

      public JavaCommandBuilder setClassPath(Path classPath)
      Register the class path that will be passed to the java command with the -cp argument.
      Parameters:
      classPath - a folder or JAR-file containing compiled classes used in the program
      Returns:
      the builder object itself for method chaining
    • addArgs

      public JavaCommandBuilder addArgs(String... args)
      Registers additional arguments for the executed program. An internal list is kept and appended in order of specification. Will be appended to the java command after the main class. It can be called multiple times.
      Parameters:
      args - varargs array of string arguments
      Returns:
      the builder object itself for method chaining
    • build

      public String[] build()
      Returns an array of strings that can be joined to a valid java command line.

      The primary intended usage is to pass it to a ProcessBuilder. This is commonly done with the Util.runCommand(java.lang.String...) abstraction method.

      Returns:
      the string array to form a java command, built by the setter methods