Class JavaCommandBuilder
java.lang.Object
org.matwoess.jsourceprofiler.common.JavaCommandBuilder
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionRegisters additional arguments for the executed program.String[]build()Returns an array of strings that can be joined to a validjavacommand line.setClassPath(Path classPath) Register the class path that will be passed to thejavacommand with the-cpargument.setMainClass(String mainClass) Register the main class name, later added as the first argument after options.
-
Constructor Details
-
JavaCommandBuilder
public JavaCommandBuilder()
-
-
Method Details
-
setMainClass
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
Register the class path that will be passed to thejavacommand with the-cpargument.- Parameters:
classPath- a folder or JAR-file containing compiled classes used in the program- Returns:
- the builder object itself for method chaining
-
addArgs
Registers additional arguments for the executed program. An internal list is kept and appended in order of specification. Will be appended to thejavacommand 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
Returns an array of strings that can be joined to a validjavacommand line.The primary intended usage is to pass it to a
ProcessBuilder. This is commonly done with theUtil.runCommand(java.lang.String...)abstraction method.- Returns:
- the string array to form a
javacommand, built by the setter methods
-