users@glassfish.java.net

Configuring PortableRemoteObject

From: <glassfish_at_javadesktop.org>
Date: Mon, 13 Aug 2007 05:24:59 PDT

Hi

I'm trying to create a new instance of an implementation of javax.rmi.PortableRemoteObject. As I understand it, in Java SE 6 you are not required to manually generate the stubs with rmic, but they are generated automatically. It seems however that this only works after an instance of InitialContext has been created. When I try to create an instance of the implementation (HelloImpl) without having created an InitialContext, it fails with a StubNotFoundException. Obviously, InitialContext does something that effects the PortableRemoteObject. What? How can I configure the PortableRemoteObject to generate the necessary stubs at runtime without creating a new InitialContext? Or am I misunderstanding something?

In short, this code works:
Context ctx = new InitialContext();
Hello hello = new HelloImpl(); //extends PortableRemoteObject
ctx.rebind("hello", hello);

But this does not:
HelloImpl hello = new HelloImpl();
Context ctx = new InitialContext(); //extends PortableRemoteObject
ctx.rebind("hello", hello);

And it produces the exception:
Exception in thread "main" java.rmi.StubNotFoundException: Stub class not found: rmi.HelloImpl_Stub; nested exception is:
        java.lang.ClassNotFoundException: rmi.HelloImpl_Stub
        at sun.rmi.server.Util.createStub(Unknown Source)
        at sun.rmi.server.Util.createProxy(Unknown Source)
        at sun.rmi.server.UnicastServerRef.exportObject(Unknown Source)
        at java.rmi.server.UnicastRemoteObject.exportObject(Unknown Source)
        at java.rmi.server.UnicastRemoteObject.exportObject(Unknown Source)
        at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.exportObject(Unknown Source)
        at javax.rmi.PortableRemoteObject.exportObject(Unknown Source)
        at javax.rmi.PortableRemoteObject.<init>(Unknown Source)
        at rmi.HelloImpl.<init>(HelloImpl.java:11)
        at rmi.Server.main(Server.java:14)
Caused by: java.lang.ClassNotFoundException: rmi.HelloImpl_Stub
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        ... 10 more
[Message sent by forum member 'krippa' (krippa)]

http://forums.java.net/jive/thread.jspa?messageID=230633