Home
Categories
Dictionary
Download
Project Details
Changes Log
Tutorials
FAQ
License

LauncherConf



The LauncherConf class allows to parse an array of argument / values usually returned in the main static method of a class, and return a map of key-value arguments.

There are two modes:
  • Without keeping the dash character at the beginning of each argument (the default mode)
  • With keeping the dash character at the beginning of each argument

Without keeping the dash character at the beginning of each argument

You can call one of the following methods:

The arguments can have one of the following pattern:
      key1 prop1 key2 prop2 ...
or
      key1=prop1 key2=prop2 ...
It is even possible to mix the two patterns such as:
      key1 prop1 key2=prop2 ...
If the value for the key is not set, then a (key, value) will be added with an empty String as value:
      key2= -key3 -key4=value4
For example, if we have:
      key1 value1 -key2=value2 -key3 key4=23
Then the method will return the following map:
  • {"key1" => "value1", "key2 => "value2", "key3" => "", "key4" => "23"}

With keeping the dash character at the beginning of each argument

To use this mode, you must call the following method: In that compatibility mode, the dash character which might be present at the beginning of each argument is not removed.

For that mode, if an argument on the command-line has a value, the value of this argument must be set in that same argument. For example, if we have:
    -key1 -key2=value2 -key3 key4=23
Then the method will return:
  • {"-key1" => "", "-key2 => "value2", "-key3" => "", "key4" => "23"}

Example

Suppose the following code for a main class:
      public class MyApp {
        public static void main(String[] args) {
          Map<String, String> theArgs = LauncherConf.getLaunchProperties(args);
        }
      }
For the launch arguments:
      java myApp -key1=1 key2=true
Then the theArgs map will contain the following elements: {"key1" => "1", "key2" => "true"}

And for the launch arguments:
      java myApp -key1 key2=true
Then the theArgs map will contain the following elements: {"key1" => "", "key2" => "true"}

See also


Categories: commandline

Copyright 2006-2023 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences