{title:'Args', created:'8.0.0', deprecated:'8.1.2'}

Command-line arguments can be associated with a microservice using the {@link oaj.microservice.Microservice.Builder#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 args = Microservice.getInstance().getArgs(); | | // One main argument | // a1 | String a1 = args.getArg(0); // "a1" | String a2 = args.getArg(1); // null | | // Two main arguments | // a1 a2 | String a1 = args.getArg(0); // "a1" | String a2 = args.getArg(1); // "a2" | | // One main argument and one optional argument with no value | // a1 -a2 | String argsa1 = args.getArg(0); | boolean hasA2 = args.hasArg("a2"); // true | boolean hasA3 = args.hasArg("a3"); // false | | // One main argument and one optional argument with one value | // a1 -a2 v2 | String a1 = args.getArg(0); | String a2 = args.getArg("a2"); // "v2" | String a3 = args.getArg("a3"); // null | | // One main argument and one optional argument with two values | // a1 -a2 v2a v2b | String a1 = args.getArg(0); | List<String> a2 = args.getArgs("a2"); // Contains ["v2a","v2b"] | List<String> a3 = args.getArgs("a3"); // Empty list | | // Same as previous, except specify optional argument name multiple times | // a1 -a2 v2a -a2 v2b | String a1 = args.getArg(0); | List<String> a2 = args.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 varResolver = Microservice.getInstance().getVarResolver(); | System.out.println(varResolver.resolve("Arg #1 is set to $A{1}"));

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