I tried implementing RMI concept using the two computers connected in my company network. I binded the remote object using my ip address and specific port number. Everything worked fine when I tried it in my local machine.
Now In order to access it from the other computer I shared the Adder (extends Remote ) interface .class file with the other computer and a client code. When I tried to access it it throwed the ClassNotFoundException: stub not found.
So I shared the stub.class file which is generated after running the command >> rmic AddImpl. After that it worked fine on the remote computer also.
Now My question is, Is that how RMI is implemented ? Do we need to share both the Adder interface and the stub class file generated in order for a client to access our remote method ?
Below are My classes and interfaces:
interface Adder extends Remote
class AddImpl extends UnicastRemoteObject implements Adder
class Server
class Client
You need to share 3 files Adder.class, Adder.java, AdderRemote_Stub.class (not the java code)
Let us assume you have compiled already
create two different directories
launch 3 command prompt
set first 2 command prompt for the first directory (server)
Example: c:\rmiserver
put all files here
set last 1 command prompt for the second directory (client)
Example: c:\rmiclient
put the client specific files, stub and remote here
(optional) set CLASSPATH=. in all command prompt
this will allow the current directory files to be recognized in CLASSPATH
important: run rmiregistry command within the command prompt where the server .class files are in CLASSPATH
run rmiregistry 5000 command in the any of the first 2 command prompt
keep it running
run your server "java MyServer" in the remaining command prompt of the first 2
run you client "java MyClient" in the last command prompt which is a different directory
if this is is working then your network logic will work
Duplicate java.rmi.ServerException: RemoteException occurred in server thread (ClassNotFoundException)