Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

LauncherUtils



The LauncherUtils class allows to parse an array of argument / values usually returned in the main static method of a class.

Arguments

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

Using a dash character before an argument

The parser understands arguments specified with or without a leading dash (minus) character. For example the following arguments declaration is valid:
      -key1=1 key2=true
Note that the parser understands that an argument without a leading dash can be an argument key of a value. For example with:
      -key1 prop1 key2=true
Then the theArgs map will contain the following element: {"key1" => "prop1", "key2" => "true"}

Example

Suppose the following code for a main class:
   public class MyApp {
     public static void main(String[] args) {
       Map<String, String> theArgs = LauncherUtils.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"}

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

See also


Categories: lang | packages

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