aspose file tools*
The moose likes Distributed Java and the fly likes RMI with JavaSE 6 - UnicastRemoteObject.exportObject(Remote object) fails Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "RMI with JavaSE 6 - UnicastRemoteObject.exportObject(Remote object) fails" Watch "RMI with JavaSE 6 - UnicastRemoteObject.exportObject(Remote object) fails" New topic
Author

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

Vivek Kr Singh
Ranch Hand

Joined: Oct 12, 2007
Posts: 56
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 ?

SCJP 1.4
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

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.


apigee, a better way to API!
Edward Harned
Ranch Hand

Joined: Sep 19, 2005
Posts: 291

Classpath.

Although the stub may be generated automatically, you still need to set a classpath (current dir, etc) for the Registry.


Ed's latest article: A Java Parallel Calamity http://coopsoft.com/ar/Calamity2Article.html
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

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

Joined: Oct 12, 2007
Posts: 56
Thanks very much for your answers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RMI with JavaSE 6 - UnicastRemoteObject.exportObject(Remote object) fails
 
Similar Threads
RMI Concepts
Exception in RMI program
RMI server startup exception
RMI in JDK6 problem
Stub cannot be cast to Interface