I am creating a Java RMI program, but getting a ClassNotFoundException. Could you guys help me figure it out? I am using Eclipse. Someone suggested to me that this is a code problem, but how does this relate? Here are the codes for my server and client:
Server:
package server; import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; import java.rmi.server.UnicastRemoteObject; import base.Server; import base.RmiStarter; public class ServerImplStarter extends RmiStarter{ public ServerImplStarter() { super(Server.class); } @Override public void doCustomRmiHandling() { try{ Server engine = new ServerImpl(); Server engineStub = (Server)UnicastRemoteObject.exportObject(engine, 0); Registry registry = LocateRegistry.createRegistry( 1099 ); registry = LocateRegistry.getRegistry(); registry.rebind("Server", engineStub); }catch(Exception e){ e.printStackTrace(); } } public static void main(String[] args){ new ServerImplStarter(); } }
Customer:
package client; import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; import base.RmiStarter; import base.Server; import base.Cell; public class CellClient extends RmiStarter { public CellClient() { super(Server.class); } @Override public void doCustomRmiHandling() { try{ Registry registry = LocateRegistry.getRegistry(); Server server = (Server)registry.lookup("Server"); Cell c = null; c = server.getcell(); }catch(Exception e){ e.printStackTrace(); } } public static void main(String[] args) { new CellClient(); } }
and the error is this:
java.rmi.UnmarshalException: error unmarshalling return; nested exception is: java.lang.ClassNotFoundException: server.CellImpl at sun.rmi.server.UnicastRef.invoke(Unknown Source) at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Unknown Source) at java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source) at $Proxy0.getcell(Unknown Source) at client.CellClient.doCustomRmiHandling(CellClient.java:23) at base.RmiStarter.<init>(RmiStarter.java:19) at client.CellClient.<init>(CellClient.java:13) at client.CellClient.main(CellClient.java:31) Caused by: java.lang.ClassNotFoundException: server.CellImpl at java.net.URLClassLoader$1.run(Unknown Source) 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 java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at sun.rmi.server.LoaderHandler.loadClass(Unknown Source) at sun.rmi.server.LoaderHandler.loadClass(Unknown Source) at java.rmi.server.RMIClassLoader$2.loadClass(Unknown Source) at java.rmi.server.RMIClassLoader.loadClass(Unknown Source) at sun.rmi.server.MarshalInputStream.resolveClass(Unknown Source) at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source) at java.io.ObjectInputStream.readClassDesc(Unknown Source) at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source) at java.io.ObjectInputStream.readObject0(Unknown Source) at java.io.ObjectInputStream.readObject(Unknown Source) at sun.rmi.server.UnicastRef.unmarshalValue(Unknown Source) ... 8 more
source share