Java args as linux args

I want to pass arguments to a java application, but as a linux application style.

The main method in java uses the String array for all parameters. On Linux, most applications accept parameters such as: ls -l --color

-l for list style output

--color is for coloring output

I want to find a code snippet for parsing a String array of a main method, such as a linux application.

I want to do something like this: java -jar myapp.jar -d arg1 --arg2

I can do it, but I don’t have time. So, if someone has the code to do this, better.

+6
source share
4 answers

You need to manually analyze the parameters or use http://commons.apache.org/cli/

+10
source

I think you want commons-cli from Apache.

+3
source

You might want to check out the Commons CLI: http://commons.apache.org/cli/

+3
source

The gnu optargs package is available. Just like its counterpart C.

+2
source

Source: https://habr.com/ru/post/887452/


All Articles