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 parameters

 
Tina Ljuslin
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody!
Can anyone please help me. I'm using the command line:
java -Djava.rmi.server.codebase=file:/c:\scjd\starting/
-Djava.rmi.server.hostname=localhost
-Djava.security.policy=java.policy suncertify.server.FBNServer
But I want to be able to set this in the code instead, does anyone know how?
Or can I use these command lines to start the server? It says in the instructions that:
These command lines may only take configuration parameters selected from this list:
DNS name of the server
Port number used by the server
Data file name(s)
java.rmi.server.codebase
security manager policy file
Please help me, I'm stuck!
//tina

 
Akanimo Udoh
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tina,
Sorry to dissappoint you but i dont really think there's anyway for you to make these settings from code. You see, those settings are required to setup the java interpreter environment to actually 'run' your code (eg codebase,policy settings).
Also in your command line i see a java.rmi.server.hostname parameter which is both not really required and not allowed as you can see from the 'allowed' parameter list in your letter.
The rest of the command line is more than adequate. If you plan to use RMI then you'll have to include the java.rmi.server.codebase property in the command line for it to work.
 
Jayakumar Duraisamy
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Akanimo,
I have seen your reply. I am just wondering why rmi.server.hostname can't be given via the java command. In my opinion, in a RMI environment we need to do that. I think what Sun mentions about "name of the DNS server" in the list makes rmi.server.hostname eligible to be a command line parameter.
It will be really appreciated, If u post any other ways of mentioning rmi hostname to the client and server.
Thanks and Regards
Jay
 
Tina Ljuslin
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm thinking of asking the user where to connect so I don't have to have it as a parameter in the commandline. I got it to work with localhost, don't know if its any different if you connect to something else.
//tina
 
Akanimo Udoh
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jay,
Lemme try and give a better explaination of what i mean. There's a difference between the "DNS name of server" in the allowed parameters and the java.rmi.server.hostname system property.
From the java documentation

java.rmi.server.hostname (1.1 and later)
The value of this property represents the host name string that should be associated with remote stubs for locally created remote objects, in order to allow clients to invoke methods on the remote object. In 1.1.7 and later, the default value of this property is the IP address of the local host, in "dotted-quad" format.

You will see that this 'system' parameter is required for the server only, so as to associate the stubs to the local objects. Since the value of this will always be localhost for the server, you don't really need to do this explicitly as this is the default.
However on the client who wants to connect to the remote server it would be incorrect to use the java.rmi.server.hostname since what you'd actually be telling the environment to do would be to associate any exported stubs to the specified server! In actuality you just want to pass the client the name of a remote system to connect to.
The latter is what is in the 'allowed' parameters list. A more correct way would be to pass as a parameter to the main method and handle from there.

Tina,
Just for the record, I want you to know that you CAN set the properties from code using System.setProperty(...) method. Though I'm not exactly sure whether the settings will be made in time for them to be used correctly. The idea of leaving them on the command line is to allow your application to be run on any particular system without modifying your code. If the testers codebase is different from your's then the code won't run on his system! Best to leave most variable stuff on the command line.
About asking the user for details its a pretty good idea. Though I believe it would be better to provide both, since having to be prompted to enter the same data over and over again everytime a user wants to connect to the same data would be a real PAIN! (this is where command lines come in handy) Remember that part of the General Considerations marks comes from "ease of use" which has 23 marks. I provided both means in my own submission and got 57/58 in General Considerations.
Akanimo.
 
Adithya Rayaprolu
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Akanimo,
You said, 'I provided both means in my own submission and got 57/58 in General Considerations.' What does 'both' mean? Did you provide command line arguments and also a dialog box asking the user to enter local or remote mode?
Thanks.
 
Jayakumar Duraisamy
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Akanimo,
Thanks for the detailed reply. I agree completely the client doesn't need to know about the rmi.server.hostname. That's was my mistake. I also agree that command line parameters has advantages.
But I believe having the application parameters via -D flag will be much better as explained below.
1.java MyClient localhost 1099 db.db

2.java -Dservername=networkname -Dport=1099 -Ddatafile=db.db is more cleaner, because user knows which value is for which flag.

In case of first one, if the user change the order, the program blows or a error message is shown.
I am not sure how you have implemented both the approaches [asking the user via dialog and also from command line], but the same can be easily implemented in the case of second.
The advantage of asking the user to input the values over command line parameters could be once we get an error in a command line approach, we need to restart the dialog again.
Thanks
Jay
 
Akanimo Udoh
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wwwADITHYA,
Let me detail what i meant by providing both options.
My client command line takes 0 parameters, 1
parameter, or 2 parameters:
a) 0 parameters
user has not specified the connection so i prompt with
a dialog asking for the type of connection
(local/remote) and the connection parameters .
b) 1 parameter
When user passes one parameter it is interpreted as a
local connection parameter ( specifically the
directory/filename ) and i attempt to connect based on
that. If that fails i still bring up the dialog.
c) 2 parameters
When user passes two parameters it is interpreted as a
remote connection command line where parameter 1 is
the serverName and parameter 2 is the portNo. I
attempt to connect based on that, it it fails up comes
the handy dialog.
In terms of 'ease of use' i think it works rather
well. Whaddayathink?
JAY,
I have to agree with you that using the -D option to
pass paramaters has advantages and seems EASIER though
I doubt that the creators of the language really meant
it to be used that way (i could be wrong???) Else
having the command line arguments passed to the main
function really wouldn't be necessary at all?. Look
thru some Java references and see how often the
command line is used to take advantage of the -D
option for non 'system' properties.
Remember that in the marking 'General Consideration'
which carries 58 marks is made up of 'coding standards
and readability' and carries 23 marks. The assignment
is not all about making the code work but also about
doing so the 'right way' (though who can claim to
really know the right way?) Just an opinion.
Akanimo.

[This message has been edited by Akanimo Udoh (edited June 29, 2001).]
 
David Reck
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could someone please explain to me why it would be better to pass in parameters like this:
java -Dhost=Me -Dport=123 ReservationSystem

Instead of creating your own flags in your program for specific parameters allowing the user to supply the parameters in any order like this:
Java ReservationSystem -HMe -P123
or
Java ReservationSystem -P123 -HMe
 
sudarshan, deshpande
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question regarding passing parameters on command line
Consider for example :
if I try to give java -D
code base location -Dsecurity policy
suncertify.server.RunServer
DNS name of the Server Port No
LOcation of Database file
On DOS prompt then I can't input all the things as shown
There is limit upto which we can input .
(I think on UNIX there is no such restriction )
So that is why I need to run a batch file ..
But as per specification it is not allowed .
Can anybody advice what may be solution ?
I guess the assignment will be tested on UNIX as well as DOS/Windows platform as well
[This message has been edited by sudarshan, deshpande (edited June 29, 2001).]
[This message has been edited by sudarshan, deshpande (edited June 29, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic