Unable to bind class to RMI registry

Discussion in 'Java' started by Robin, Apr 24, 2006.

  1. Robin

    Robin Guest

    I'm not sure I understand the exceptions being thrown here. I need a
    connection between two servers and I chose to use RMI. Whenever I try
    to run the code that starts the "RMI Server" I am getting an exception.
    I will post the code, and then the exceptions. Hopefully someone can
    see an error - I cannot.

    Interface:

    public interface G2RemoteInterface extends Remote {
    public InquiryConfig getConfig(String configFile) throws
    RemoteException;
    public Response makeRequest(G2Request request) throws
    RemoteException;
    }

    Implementation:

    public class G2Remote implements G2RemoteInterface, Serializable {
    private static final long serialVersionUID = 2530016775139934837L;

    public G2Remote() throws RemoteException {
    System.out.println("G2Remote Object Constructed");
    }

    public InquiryConfig getConfig(String configFile) throws
    RemoteException {
    InquiryConfig config = new InquiryConfig();
    try {
    config.load(configFile);
    } catch (Exception e) {
    e.printStackTrace();
    }
    return config;
    }

    public Response makeRequest(G2Request request) throws RemoteException
    {
    try {
    return request.runDataHandler();
    } catch (Exception e) {
    e.printStackTrace();
    return null;
    }
    }
    }

    Server to launch this:

    public class G2RemoteServer {

    public static void main(String[] args) {
    try {
    //System.out.println("feh");
    Naming.rebind("G2Remote", new G2Remote());
    System.out.println("G2 Remote Server running...");
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }




    I do have rmiregistry running before the server is ever called. When I
    do run it, I get this error:

    G2Remote Object Constructed
    java.rmi.ServerException: RemoteException occurred in server thread;
    nested exception is:
    java.rmi.UnmarshalException: error unmarshalling arguments; nested
    exception is:
    java.lang.ClassNotFoundException:
    tpc.circulation.discus.g2.remote.G2Remote
    at
    sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:385)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:240)
    at sun.rmi.transport.Transport$1.run(Transport.java:153)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
    at
    sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
    at
    sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
    at java.lang.Thread.run(Thread.java:595)
    at
    sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown
    Source)
    at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
    at sun.rmi.server.UnicastRef.invoke(Unknown Source)
    at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
    at java.rmi.Naming.rebind(Unknown Source)
    at
    tpc.circulation.discus.g2.remote.G2RemoteServer.main(G2RemoteServer.java:26)
    Caused by: java.rmi.UnmarshalException: error unmarshalling arguments;
    nested exception is:
    java.lang.ClassNotFoundException:
    tpc.circulation.discus.g2.remote.G2Remote
    at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
    at
    sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:375)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:240)
    at sun.rmi.transport.Transport$1.run(Transport.java:153)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
    at
    sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
    at
    sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
    at java.lang.Thread.run(Thread.java:595)
    Caused by: java.lang.ClassNotFoundException:
    tpc.circulation.discus.g2.remote.G2Remote
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:242)
    at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:430)
    at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:165)
    at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:620)
    at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:247)
    at
    sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.java:197)
    at
    java.io_ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1538)
    at
    java.io_ObjectInputStream.readClassDesc(ObjectInputStream.java:1460)
    at
    java.io_ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1693)
    at java.io_ObjectInputStream.readObject0(ObjectInputStream.java:1299)
    at java.io_ObjectInputStream.readObject(ObjectInputStream.java:339)
    ... 9 more



    I hope someone can help.

    Cheers,

    Robin
    Robin, Apr 24, 2006
    #1
    1. Advertising

  2. Robin

    Jeroen V. Guest

    You should generate stubs (using rmic) & deploy them with your application.
    Jeroen V., Apr 24, 2006
    #2
    1. Advertising

  3. Robin

    Robin Guest

    I should have mentioned that I was building the Stub's and Skel's.
    Interesting -- when I build via an ANT script I only get the stub, but
    if I do an rmic on the command line I'm getting both Stub's and Skel's.

    Robin
    Robin, Apr 24, 2006
    #3
  4. Robin

    Robin Guest

    If anyone is reading this thread - I found the reason for my error.

    I was starting rmiregistry in one terminal window, while launching the
    server in another. When launching the server I used a -classpath
    option for my java command.

    The problem was that my CLASSPATH env variable was not set correctly
    when I was starting rmiregistry. Even though I'm not relying on it for
    running the server, it must be there for the registry.

    This worked:
    $ CLASSPATH=/path/to/jars ; export CLASSPATH
    $ rmiregistry &
    $ java -cp $CLASSPATH the.rmi.server.ClassName

    Robin
    Robin, Apr 24, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. HK
    Replies:
    1
    Views:
    3,605
    Cowboy \(Gregory A. Beamer\)
    Apr 1, 2004
  2. Replies:
    0
    Views:
    733
  3. Leny
    Replies:
    3
    Views:
    16,904
    Daniel
    Feb 1, 2005
  4. Jan Schulze
    Replies:
    1
    Views:
    562
    Esmond Pitt
    Mar 26, 2005
  5. Collin Miller
    Replies:
    10
    Views:
    580
    Roger Pack
    Jul 9, 2010
Loading...

Share This Page