Add to Google Reader or Homepage

Executing an RMI

How to execute a RMI program?


There are three steps involved in executing a RMI program,

1. Executing the RMI registry

2.Executing the server

3 Executing the Client


1)Executing the RMI registry



 In windows type in,

c:\>rmiregistry  and press enter key, then the RMI registry will  get started

 

2)Executing the server


Executing a RMI server is quite difficult for newbies. In my previous post RMI tutorial i told you that if a client requires a remote object then it will request the object from the RMI registry with a name.


 who is registering the remote object in the RMI registry?

The answer is server,  but when the server is registering the object it needs to provide the details about the location of the classes and interfaces that may be required  by the remote object. Otherwise javax.naming.communicationexception will be thrown. So in order to avoid this error you need to provide the location of the required classes using the codebase property.


There are two ways to do that,

Way 1:

 Here if you see the line,

java -Djava.rmi.server.codebase=http://localhost:80/ NameServer.




I am saying to the registry that all the required files will be available in the port 80 of this system  using the url http://localhost:80/ . Since i have implemented this in a single system i have done like this, but this will be more useful when the required files are available in another remote machine. At that time you have to specify the hostname of the remote machine in the url like as follows,

http://metallica:80/  if the host name is metallica.


Way 2: 

When all the required files are available in the server itself then you don't need to provide the url but you have to provide the location of the class files in the server like as follows


Since my class files are available in the location file:c:\blog\rmi1\downloads/  i have given like this, so during execution of the server all the required files will be downloaded from the given location.


Executing a client:


It is simple as executing the normal java program,say for an example java NameClient


 

0 comments:

Post a Comment

 
java errors and exceptions © 2010 | Designed by Chica Blogger | Back to top