1 Reply Latest reply: Mar 27, 2011 7:02 PM by EJP RSS

    RMI problem: java.lang.ClassNotFoundException: Interface

    850654
      Hi, i am encountering some difficulties to set a RMI communication, this is my code:

      Server:+
      public class ServerRMI { 
      public static final int numPortRMIRegistry = 1099;

      public static void main(String[] args) { 

      try { 
      LocateRegistry.createRegistry(numPortRMIRegistry);

      System.setSecurityManager ( new RMISecurityManager() );

      DAOInt<Joueur> joueur = new DAOJoueur();

      Naming.rebind("rmi://localhost/game", joueur);

      } catch (Exception e) { 
      e.printStackTrace();
      }
      }
      }


      Client:+

      public class ClientRMI { 

      final int PORT = 1099;

      public Joueur getJoueur(String Login)


      Joueur jou = new Joueur();
      try { 
      LocateRegistry.getRegistry(PORT);
      System.setSecurityManager ( new RMISecurityManager() );

      Remote r = Naming.lookup("rmi://localhost/game");

      DAOInt<Joueur> joueur = (DAOInt<Joueur>) r;

      jou = joueur.read(Login); // for DB..

      return jou;

      } catch (Exception e) { 
      e.printStackTrace();
      }
      return null;
      }
      }

      I run rmic thanks to my build.xml "*Ant*"
      <rmic classname="dao.DAOJoueur" base="${classes}" />



      it gives Stub and Skeleton, but when i execute this i get this error on my client:

      java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
      java.lang.ClassNotFoundException: dao.DAOInt
      at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
      at java.rmi.Naming.lookup(Unknown Source)
      at clientMetierServ.ClientRMI.getJoueur(ClientRMI.java:26)
      at serverMertierServ.RequestStatement.run(RequestStatement.java:61)
      at java.lang.Thread.run(Unknown Source)


      I note that dao.DAOInt is located on my server !


      Can someone help me Please
        • 1. Re: RMI problem: java.lang.ClassNotFoundException: Interface
          EJP
          There are several issues with that code, but my first question would be about the package statements. It looks to me like you have declared the remote interface in two packages at once. You can't do that. The remote interface used by the client has to be exactly the same as the remote interface implemented by the server.

          Some of the issues:
          LocateRegistry.createRegistry(numPortRMIRegistry); 
          The result of that method must be stored in a static variable. Otherwise the Registry is liable to exit any time.
          System.setSecurityManager ( new RMISecurityManager() ); 
          You don't need a security manager in the server unless the client sets the java.rmi.server.codebase system property.
          LocateRegistry.getRegistry(PORT); 
          Calling that method and just throwing away the result achieves precisely nothing. All it does is create a Registry stub to the host:port specified. Specifically it doesn't do any network I/O so it doesn't constitute an existence proof.
          System.setSecurityManager ( new RMISecurityManager() ); 
          You don't need a security manager in the client unless the server sets the java.rmi.server.codebase system property.