1

I'm coding a tool in java that need some input passed by args[] I know how to use argument but i wish to handle better this input.

this is a part of my code:

if (args.length > 0 ) {

        switch (args[0]) {

        case "scan": blah blah
        break;
        case "some cases": some code
        break;

but of course args are strictly bounded to their position, in fact in the command line i have to call:

java javaProgram arg1 arg2 arg3

i really don't like this...

What i want is to better manage this arguments with options like any other c programmed tool, indipendent from positions:

example:

java javaProgram -ip 127.0.0.1 -database data.txt -vv -out output.txt

any help will be appreciated!

Dave

(i'm thinking about an array list of arguments, can be a solution?)

0

1 Answer 1

7

Use Apache Commons CLI Builder .

Sign up to request clarification or add additional context in comments.

3 Comments

yes but any good guide? it is very interesting!
I've had some good results from JSAP as well, but it seems outdated one person lib - that said, it does work and is kind of object-orientated. You could use it if CLI builder does not suit your needs.
The cool thing about CLI Builder is the "fluent api" syntax.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.