Class ArgsVar


public class ArgsVar extends DefaultingVar
JVM args variable resolver.

The format for this var is "$A{arg[,default]}".

This variable resolver requires that the command-line arguments be made available through any of the following:

  • "sun.java.command" system property.
  • "juneau.args" system property.
  • init(Args) has been called.
Example:

// Create an args object from the main(String[]) method. Args args = new Args(argv); ArgsVar.init(args); // Create a variable resolver that resolves JVM arguments (e.g. "$A{1}") VarResolver varResolver = VarResolver.create().vars(ArgsVar.class).build(); // Use it! System.out.println(varResolver.resolve("Arg #1 is set to $A{1}"));

Since this is a SimpleVar, any variables contained in the result will be recursively resolved. Likewise, if the arguments contain any variables, those will be resolved before they are passed to this var.

See Also:
  • Field Details

  • Constructor Details

    • ArgsVar

      public ArgsVar()
      Constructor.
  • Method Details

    • init

      public static void init(Args args)
      Initialize the args for this variable.
      Parameters:
      args - The parsed command-line arguments.
    • resolve

      public String resolve(VarResolverSession session, String key)
      Description copied from class: Var
      The interface that needs to be implemented for subclasses of SimpleVar.
      Specified by:
      resolve in class Var
      Parameters:
      session - The session object used for a single instance of a var resolution.
      key - The inside argument of the variable.
      Returns:
      The resolved value.