Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RMI with JavaSE 6 - UnicastRemoteObject.exportObject(Remote object) fails

 
Vivek Kr Singh
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

According to javadoc for java.lang.UnicastRemoteObject, UnicastRemoteObject.exportObject(Remote object)
Exports the remote object to make it available to receive incoming calls using an anonymous port.


Here is the Server Class:


Error Trace:
java.rmi.StubNotFoundException: Stub class not found: com.vivek.core.rmi.server.HelloWorldServer_Stub; nested exception is:
java.lang.ClassNotFoundException: com.vivek.core.rmi.server.HelloWorldServer_Stub

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


Would someone guide me why this is happening ?
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per these release notes:

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.
 
Edward Harned
Ranch Hand
Posts: 291
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Classpath.

Although the stub may be generated automatically, you still need to set a classpath (current dir, etc) for the Registry.
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Edward Harned wrote:Although the stub may be generated automatically, you still need to set a classpath (current dir, etc) for the Registry.


Not atleast for the dynamic proxy.
 
Vivek Kr Singh
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much for your answers.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic