Args

Command-line arguments can be associated with a microservice using the {@link oaj.microservice.MicroserviceBuilder#args(String...)} method.

##### Example:

public static void main(String[] args) { Microservice .create() // Create builder. .args(args) // Pass in args. .build() // Create microservice. .start() // Start microservice. .join() // Join thread. ; }

When specified, the arguments can be retrieved using the {@link oaj.microservice.Microservice#getArgs()} method which provides an API for easily accessing command-line arguments using common notation:

Args a = Microservice.getInstance().getArgs(); // One main argument // a1 String a1 = a.getArg(0); // "a1" String a2 = a.getArg(1); // null // Two main arguments // a1 a2 String a1 = a.getArg(0); // "a1" String a2 = a.getArg(1); // "a2" // One main argument and one optional argument with no value // a1 -a2 String a1 = a.getArg(0); boolean hasA2 = a.hasArg("a2"); // true boolean hasA3 = a.hasArg("a3"); // false // One main argument and one optional argument with one value // a1 -a2 v2 String a1 = a.getArg(0); String a2 = a.getArg("a2"); // "v2" String a3 = a.getArg("a3"); // null // One main argument and one optional argument with two values // a1 -a2 v2a v2b String a1 = a.getArg(0); List<String> a2 = a.getArgs("a2"); // Contains ["v2a","v2b"] List<String> a3 = a.getArgs("a3"); // Empty list // Same as previous, except specify optional argument name multiple times // a1 -a2 v2a -a2 v2b String a1 = a.getArg(0); List<String> a2 = a.getArgs("a2"); // Contains ["v2a","v2b"]

Specifying the command-line arguments also makes them available through {@link oaj.svl.vars.ArgsVar $A} SVL variables. These can be used in the configuration file and throughout various Juneau annotations.

##### Example:

// $A used in variable resolver. VarResolver vr = Microservice.getInstance().getVarResolver(); System.out.println(vr.resolve("Arg #1 is set to $A{1}"));

// $A used in annotation. @Rest( title="$A{title}", ... )