Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Command Line Arguments

 
Donald Wedding
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I plan to use flags in my command line arguments such as this:
java mySCJDcode -host=1.2.3.4 -port=5678
This way I'll be able to determine what mode the user wants to run the program in (I know I can count the arguments, but I prefer this way).
Has anybody tried this and were they penalized for this approach?
Thanks!
 
HenkGijsbert
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Donals,
Imho, if we have the same assignment, we are not allowed to specify the -host, so it would be penalized. In my instructions the allowed parameters are:
-DNS name of the server
-Port number used by the server
-Data file name(s)
-java.rmi.server.codebase
-security manager policy file
So what I plan to do is to parse the DNS name of the server, for instance //someHost/DataServer to find out the host. Does anyone have a better idea? Or should we make a provision in our UI to specify the hostname, like someone mentioned in an earlier posting?
Regards,
Henk
 
Steve Granton
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I thought that by 'DNS name of server' they meant the physical server that was hosting the server for the project? Surely the in the URL //someHost/DataServer the DNS name would be 'someHost'? Correct me if I'm wrong.
In my experience using flags can get messy as you need to parse the command line arguments - unix has a utility getopts to do this and there are implementations written in java which you could use in your code but I don't know if we can use 3rd party libraries.
Instead of using flags should we be passing in the configuration parameters by using the -D option to java? Then the parameters would be available as properties in the JVM? You simply test whether the properties are set before using them.
Cheers,
Steve
 
HenkGijsbert
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve,
You're right, it is the physical server, I was mistaking .
-D properties indeed is an option. I chose flags however, because it feels more like a startup thing to me, than an environment thing.
Regards,
Henk
 
Steve Granton
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats fine,
I just noticed that some application servers, i.e. Websphere and J2EE Reference Server from Sun use the -D option in their startup scripts.
The advantage of using this approach is that you can vary the number of parameters you pass in and once in the application you don't have to parse the command line args - you simply test for existence by using System.getProperty(String key) method, which returns null if its not set. I think it looks tidier in the code.
The downside to using the -D is that the command line can become quite long quite quickly.
Cheers,
Steve
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic