• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

command line arguments

 
Andrea Gazzarini
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Although the requirements says "These command lines may only take configuration parameters selected from this list..." this doesn't tell the way I must use to distinguish between a server name and for example a database file path. I've
used this approach:
java MyLauncher -db C:\pippo\db.db -server pluto -port 2123
(Obviously this is an example...in the real implementation I can't supply either the db file and the server name or port)
Is this right?
Thanks
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure if this will help, but I took the easy way out.
The only argument that you can pass in mine is the IP Address/Server name if you wanted it in remote mode.
The location of the db.db file was always the root directory where the jar files are, so in my code, it is as simple as just db.db. I also took the default port for RMI.
My Factory class to get a DataAccess class would see if args[] had a value, then use it as the server address. If no value then start in local mode.
Others have made the client with no args, and a screen starts by having the user enter the server address/port and/or location of the db.db file, and take that information and run Local or Remote.
Mark
 
Andrea Gazzarini
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark! Thanks for the reply...
Although your approach seems OK, I have coded a lot of wrapping,parsing and validating classes with the approach described in the post.
Would you think my command line is wrong?
Thanks.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I don't think the -db or the -server is necessary.
Remember in Public Static Void Main the argument is a String array which is the command line arguments passed.
In your read me you can say to run
java -jar client.jar <<put db location here>> <<put server location here>> <<put port here>>
Mark
 
Andrea Gazzarini
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark!
java -jar client.jar <<put db location here>> <<put server location here>> <<put port here>>

...and what happens if I type
java MyMain pippo
(my intention is to start the application in remote mode with a remote server called "pippo"...pippo isn't the name of the database file...!)
In other words, How do you can objectively assign a mean to the argunents supplied by some user??
I think the insertion of arguments name is a good idea (-db, -server, -port). For some parameters I have supplied a default value...so there is a default value for the server name (localhost), the port number (1099) but there isn't for the database file: if you type
java -MyClass

the application starts in remote mode and tries to locate a server running on localhost:1099
If you want to start the application in local mode you must supply the database lkocation with the - db option.
Thanks anyway
 
Miguel Roque
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all.
My idea to solve this is just don't use command line arguments. Instead, when the program starts it shows a dialog where i've placed a tabbed pane. One for local mode and other for network. Depending on the selected pane, i ask for the relevant information. I will save that information in a parameters file so that the next time the program starts, the default execution will be the one that is in the parameters file.
I think that's the most user friendly approach that one can have. Maybe after all i can put command line arguments so that the user can bypass this dialog box, but if i do it it will be something like:
java FBNClient -db=<db location>
or
java FBNClient -server=<server url> -port=<server port>
Best regards,
Miguel
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...and what happens if I type
java MyMain pippo

Andrea, that is actually how my submission worked. You could either put a server address or nothing. But I will say this
In WIndows, if I have an icon that points to c:\myprogram\my.exe and I don't have a my.exe in that directory, then it fails. It is not a poor desing in the my.exe, it is just the running of the program was done wrong.
In the readme.txt they specifically ask you to give them the command line to start your app in remote and local. That is all, if the assessor decides to type that in incorrectly, it is not a reflection on you. Now on a note to that, if the Assessor were to type in incorrectly the Server or Client won't start, and in my Exception ahndling they will get a nice neat Popup Window stating in User understandable words that the App did not start.
And Miguel has the solution to remove Command Line Arguments.
Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic