Results 1 to 2 of 2
  1. #1
    Swiftslide is offline Member
    Join Date
    Apr 2011
    Posts
    1
    Rep Power
    0

    Question RMI - getting ClassNotFoundException for my remote interface

    I'm going through the tutorial at Getting Started Using Java RMI . Reason is that I am having great problems running an application of my own that uses RMI. I thought I'd go back to basics and see if I could work out what's wrong.
    And lo and behold, I can't get the tutorial to run, either!
    That's not entirely true: I have got it to run once. Silly me, I didn't record what I did to make it run, and can't replicate this momentous feat.

    Anyway...

    The tutorial includes all the code: I have written none of it, edited none of it, so for once I cannot be blamed for bad coding. I am trying to get the server class to run. The code is:

    Java Code:
    package example.hello;
    	
    import java.rmi.registry.Registry;
    import java.rmi.registry.LocateRegistry;
    import java.rmi.RemoteException;
    import java.rmi.server.UnicastRemoteObject;
    	
    public class Server implements Hello {
    	
        public Server() {}
    
        public String sayHello() {
    	return "Hello, world!";
        }
    	
        public static void main(String args[]) {
    	
    	try {
    	    Server obj = new Server();
    	    Hello stub = (Hello) UnicastRemoteObject.exportObject(obj, 0);
    
    	    // Bind the remote object's stub in the registry
    	    Registry registry = LocateRegistry.getRegistry();
    	    registry.bind("Hello", stub);
    
    	    System.err.println("Server ready");
    	} catch (Exception e) {
    	    System.err.println("Server exception: " + e.toString());
    	    e.printStackTrace();
    	}
        }
    }
    The code for the "Hello" interface is simply:

    Java Code:
    package example.hello;
    
    import java.rmi.Remote;
    import java.rmi.RemoteException;
    
    public interface Hello extends Remote {
        String sayHello() throws RemoteException;
    }
    I keep all this in a file on my desktop (makes for short URIs):

    Java Code:
    C:\Users\Benji\Desktop\hello
    Therefore the three .class files, when compiled, are located in:

    Java Code:
    C:\Users\Benji\Desktop\hello\example\hello
    I first start the RMI registry at the command line, using

    Java Code:
    start rmiregistry
    Then I execute a batch file located in C:\Users\Benji\Desktop\hello, which has the following lines:

    Java Code:
    java -classpath C:\Users\Benji\Desktop\hello example.hello.Server
    pause
    I have also tried executing from the command line, by doing:

    Java Code:
    cd C:\Users\Benji\Desktop\hello
    And then:

    Java Code:
    java -classpath . example.hello.Server
    Whatever method I use, I (almost) inevitably am met with the following bog of errors:

    Java Code:
    Server exception: java.rmi.ServerException: RemoteException occurred in server t
    hread; nested exception is:
            java.rmi.UnmarshalException: error unmarshalling arguments; nested excep
    tion is:
            java.lang.ClassNotFoundException: example.hello.Hello
    java.rmi.ServerException: RemoteException occurred in server thread; nested exce
    ption is:
            java.rmi.UnmarshalException: error unmarshalling arguments; nested excep
    tion is:
            java.lang.ClassNotFoundException: example.hello.Hello
            at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:396
    )
            at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:250)
            at sun.rmi.transport.Transport$1.run(Transport.java:159)
            at java.security.AccessController.doPrivileged(Native Method)
            at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
            at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:5
    35)
            at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTranspor
    t.java:790)
            at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport
    .java:649)
            at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExec
    utor.java:886)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
    .java:908)
            at java.lang.Thread.run(Thread.java:662)
            at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Stream
    RemoteCall.java:255)
            at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:
    233)
            at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:359)
            at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)
            at example.hello.Server.main(Server.java:61)
    Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested ex
    ception is:
            java.lang.ClassNotFoundException: example.hello.Hello
            at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
            at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:386
    )
            at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:250)
            at sun.rmi.transport.Transport$1.run(Transport.java:159)
            at java.security.AccessController.doPrivileged(Native Method)
            at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
            at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:5
    35)
            at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTranspor
    t.java:790)
            at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport
    .java:649)
            at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExec
    utor.java:886)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
    .java:908)
            at java.lang.Thread.run(Thread.java:662)
    Caused by: java.lang.ClassNotFoundException: example.hello.Hello
            at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
            at java.lang.Class.forName0(Native Method)
            at java.lang.Class.forName(Class.java:247)
            at sun.rmi.server.LoaderHandler.loadProxyInterfaces(LoaderHandler.java:7
    11)
            at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:655)
            at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:592)
            at java.rmi.server.RMIClassLoader$2.loadProxyClass(RMIClassLoader.java:6
    28)
            at java.rmi.server.RMIClassLoader.loadProxyClass(RMIClassLoader.java:294
    )
            at sun.rmi.server.MarshalInputStream.resolveProxyClass(MarshalInputStrea
    m.java:238)
            at java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1530)
            at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1492)
            at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1
    731)
            at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
            at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
            ... 12 more
    Anyone know what's going on? Pretty please? :eek:

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,271
    Blog Entries
    7
    Rep Power
    24

    Default

    Quote Originally Posted by Swiftslide View Post
    Java Code:
            java.lang.ClassNotFoundException: example.hello.Hello
    Anyone know what's going on? Pretty please? :eek:
    Isn't the name of your server example.hello.Server? Also, is that interface Hello.class available at your server?

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

Similar Threads

  1. ClassNotFoundException
    By meprasobh in forum New To Java
    Replies: 2
    Last Post: 10-17-2010, 03:32 PM
  2. classNotFoundException
    By jyothi.priyanka in forum NetBeans
    Replies: 5
    Last Post: 08-24-2010, 10:13 AM
  3. ClassNotFoundException
    By oontvoo in forum Java Applets
    Replies: 7
    Last Post: 05-13-2010, 11:09 PM
  4. Remote deploy and remote work with JBoss AS
    By chalda in forum Eclipse
    Replies: 2
    Last Post: 03-08-2010, 12:17 PM
  5. Remote interface for entity bean
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-28-2007, 11:40 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •