I am working with RMI on JAVA SE 6 by following this guide. Currently i am facing exception when i try to use UnicastRemoteObject.exportObject(Remote object) whereas UnicastRemoteObject.exportObject(Remote object, Port port) is successfull.
Exports the remote object to make it available to receive incoming calls using an anonymous port.
Here is the Server Class:
java.rmi.StubNotFoundException: Stub class not found: com.vivek.core.rmi.server.HelloWorldServer_Stub; nested exception is:
There is no need for "rmic" as in the same document it is mentioned
Note: As of the J2SE 5.0 release, stub classes for remote objects no longer need to be pregenerated using the rmic stub compiler, unless the remote object needs to support clients running in pre-5.0 VMs. If your application needs to support such clients, you will need to generate stub classes for the remote objects used in the application and deploy those stub classes for clients to download
The static method UnicastRemoteObject.exportObject(Remote) is declared to return java.rmi.server.RemoteStub and therefore cannot be used to export a remote object to use a dynamically generated stub class for its stub. An instance of a dynamically generated stub class is a java.lang.reflect.Proxy instance which is not assignable to RemoteStub.
So, either you have to extend UnicastRemoteObject or use UnicastRemoteObject.exportObject(Remote object, Port port) which you have already discovered to be working.