• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

need to parse command line parameters in my code

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please suggest how should i.. some one said gnu lib. can anyone give me a little idea of this and cmd...have no clue...
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The command-line arguments come in as an array of String objects in the main method of the class you execute with Java. I've always just checked the length of the argument array and invoked "return" if I don't have the correct number of arguments. If you have a more complex command line with many options, you may want to look at a helper library like Jakarta Common's CLI (CLI stands for Command Line Interface).
 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As far as command line arguments are concerned, you may teach yourself in a minute here.
 
asit sheth
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Joe Ess:
The command-line arguments come in as an array of String objects in the main method of the class you execute with Java. I've always just checked the length of the argument array and invoked "return" if I don't have the correct number of arguments. If you have a more complex command line with many options, you may want to look at a helper library like Jakarta Common's CLI (CLI stands for Command Line Interface).



My problem is that I cannot use a String[] args type sol. i will be apssing them via a switch like -d 1 -u 7 etc. here another situation may be if i want to pass a negative number like -1 how would i.. for the parser would interpret it as negative. can i use the gnu lib.. if so how.. caould any one tell me where i can find reading materail on this...
thanks for reading and Would really appreciate your help
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by asit sheth:
some one said gnu lib.

No doubt they were referring to the Java port of the GNU GetOpt C Library.

I have no idea how this compares with the tool Joe mentioned -- did you look at it?
 
asit sheth
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by David Harkness:
No doubt they were referring to the Java port of the GNU GetOpt C Library.

I have no idea how this compares with the tool Joe mentioned -- did you look at it?



ya.. it is on the same lines i guess. it uses an options object that identifies parameters as -o etc. but first i got to create an options object and since i am making a generic tool which can be used by any project i would want to give some sort of flexibility to the user in terms of him entering whatever he wants and me parsing it. One way out here is take the list of cmd param via an xml containing other stuff also like path of log files etc. but i was wondering if there was another way out. also if i use switch like -d etc, how can i pass a negative value like -u -u where "-u" is the value of param u. anyideas...
thanks for reading..
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It sounds like you want to write your own getopt library for others to use. If that's the case, clearly you'll be starting from scratch and using the standard Java parsing libraries. Can you describe your project in a bit more detail?
 
asit sheth
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by David Harkness:
It sounds like you want to write your own getopt library for others to use. If that's the case, clearly you'll be starting from scratch and using the standard Java parsing libraries. Can you describe your project in a bit more detail?



sure.. I am trying to create an app initiator that can be used by other java programs to set up the environ ment for them. it will recieve an xml file containing paths of config files, log files and database credentials. my app will connect to the database Oracle and give the user a GUI to choose which tables and which fields (with their dependencies) he wishes to represent in the java code. then i can create a set of java classes for them mapping to the tables with getter and setter methods for the instance fields. the app will also provide a generic interface by which the user can choose which other databse he wishes to connect to and custom his application from that..can i generate java code for any database at run time..? i dint think so, so i opted this way. then i set up the logging and store the config file information for them and they can retreive it by methods in an interface. and lastly i create a database connection for them which they can retreive from the interface and use as they wish. finally i would invoke their application by reflection......in all this fucntionality i also have a part that caters to aprsing command line aargs passed and store them in a hashtable to be used later by implementing application. hence the confusion
On another thread ......
this is my company project, was thinking on the same lines so had a wild idea..
istead of parsing a xml, if i parse a word document (template will be fixed from before) and extract methods and classes to be used along with database credentials. then instead of just generating the database interaction code i can generate the entire package structures with class and methods along with signatures. all the user will have to do is plug in his code in the method braces. so it will be like a tool which will create a project from a design document. what do you say.. was thinking of building it myself as a practise thing. do you think it will be useful and is it a good idea..
Thanks
 
asit sheth
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I forgot to mention in my reply...:
have a years experince in the industry and am gearing up for my scjp end of the month. and am also planning to take on the scjd after a few months of that. so i thought the practice may help..plus i would love to create something like that that can be of utility
 
My previous laptop never exploded like that. Read this tiny ad while I sweep up the shards.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic