0

Need to pass command line args as a key value. As I have 6-7 input arguments of different type and I dont remember the key name if I accept them as a array of string

public void main(String arg[]){}

How can I fetch key value pair without doing any split or anything. Is there a library that supports fetching value of arguments by passing key name.

In what format I should pass? In what format I should fetch data passing key ?

  • For example: `java -jar myApplication.jar 10` where `"10"` would be available at `arg[0]` (remember everything passed is `String`). You can start here: https://www.baeldung.com/java-run-jar-with-arguments. And then take a look to this: https://stackoverflow.com/questions/7341683/parsing-arguments-to-a-java-command-line-program – Nikolas Charalambidis Jan 15 '21 at 12:17
  • You could always do it as `-Dkey=value` where `key` shows up as a property. Otherwise, do straight command line parsing. There are a number of libs out there. – Erik Jan 15 '21 at 12:18
  • 1
    Your question would be easier to answer if you would edit it and add an example of the command line arguments you’re expecting. – VGR Jan 15 '21 at 14:26

0 Answers0