I plan to use flags in my command line arguments such as this: java mySCJDcode -host=188.8.131.52 -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!
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
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
posted 18 years ago
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
posted 18 years ago
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
No one can make you feel inferior without your consent - Eleanor Roosevelt. tiny ad:
Devious Experiments for a Truly Passive Greenhouse!