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?)

AeonDave
  • 781
  • 1
  • 8
  • 17

1 Answers1

7

Use Apache Commons CLI Builder .

djangofan
  • 28,471
  • 61
  • 196
  • 289
  • yes but any good guide? it is very interesting! – AeonDave Dec 06 '12 at 03:12
  • I've had some good results from [JSAP](http://www.martiansoftware.com/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. – Maarten Bodewes Dec 06 '12 at 03:13
  • The cool thing about CLI Builder is the "fluent api" syntax. – djangofan Aug 08 '13 at 15:38