Link to home
Start Free TrialLog in
Avatar of learningunix
learningunix

asked on

parsing command line options in Java

i want to write an application

java -jar TEST.jar -u username -h host   etc.....

can someone point me to example of parsing this.
Avatar of Cong Minh Vo
Cong Minh Vo
Flag of Viet Nam image

Avatar of learningunix
learningunix

ASKER

I don't have

import org.apache.commons.cli.*;

Is ther any way without inastalling new java packages?
public class Echo {
    public static void main (String[] args) {
        for (String s: args) {
            System.out.println(s);
        }
    }
}
http://download.oracle.com/javase/tutorial/essential/environment/cmdLineArgs.html
I am looking something similar to waht we have in C++ GetOpt
If you organise the args well (as you have) then you should be able to use a Map
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I just downloaded jot-simple.
I'll give it a try and see

so when I create my own jar file do I have to give all class file of jotsimple also ?
>>
I just downloaded jot-simple.
I'll give it a try and see
>>

I thought you didn't want to install extra software..?
I'll try both and see.

Today is my first day of java programming and trying to do too many things at once and probably jumping a lot.
>>Today is my first day of java programming

In that case keep it simple: use what i posted and you can go for a more reusable and extensible solution later
I found one more tool
jargs.gnu which is also good one.
Thanks, I am planning to use jargs.gnu as it is fairly simple.

Thanks once again for the direction.
:)