Ciao a tutti, ho fatto un programmino di test per l'rmi è ho l'eccezione da titolo,vi ricopio il codice, sto usando netbeans con 3 progetti, uno è il server uno il client e l'altro è l'interfaccia remota...ho linkato l'interfaccia remota per avere il riferimento sia nel server che nel client:
Client:
Interfaccia:codice:package rmi.client; import java.net.MalformedURLException; import java.rmi.Naming; import java.rmi.NotBoundException; import java.rmi.RemoteException; import rmi.shared.IRemoteInterface; public class RMIClient { /** * @param args the command line arguments */ public static void main(String[] args) throws NotBoundException, MalformedURLException, RemoteException{ IRemoteInterface server = (IRemoteInterface)Naming.lookup("RMIService"); server.output(); } }
Server:codice:package rmi.shared; import java.rmi.Remote; import java.rmi.RemoteException; public interface IRemoteInterface extends Remote { public void output()throws RemoteException; }
StartServer:
ServerClass:codice:import java.net.MalformedURLException; import java.rmi.Naming; import java.rmi.RemoteException; import rmi.server.ServerClass; public class StartServer { public static void main(String[] args)throws RemoteException,MalformedURLException { ServerClass server; server = new ServerClass(); Naming.rebind("RMIService",server); System.out.println("Servers Started"); } }
l'errore avviene all'avvio della classe startserver, ho passato questi argomenti:codice:package rmi.server; import java.rmi.RemoteException; import java.rmi.server.UnicastRemoteObject; import rmi.shared.IRemoteInterface; public class ServerClass extends UnicastRemoteObject implements IRemoteInterface{ public ServerClass() throws RemoteException { } @Override public void output(){ System.out.println("Ciao! Sono il server che ti parla"); } }
StartServer: -Djava.rmi.server.codebase="file://${workspace_loc:RMI-Shared}/bin/ file://${workspace_loc:RMI-Server}/bin/"
RMICLient: -Djava.security.policy=client.policy
naturalmente ho creato pure il policy
l'eccezione è questa:
codice:Exception in thread "main" java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: java.lang.ClassNotFoundException: rmi.shared.IRemoteInterface at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:419) at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:267) at sun.rmi.transport.Transport$1.run(Transport.java:177) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Transport.java:173) at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:679) at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:273) at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:251) at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:377) at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source) at java.rmi.Naming.rebind(Naming.java:177) at StartServer.main(StartServer.java:13) Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: java.lang.ClassNotFoundException: rmi.shared.IRemoteInterface at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source) at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:409) at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:267) at sun.rmi.transport.Transport$1.run(Transport.java:177) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Transport.java:173) at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:679) Caused by: java.lang.ClassNotFoundException: rmi.shared.IRemoteInterface at java.net.URLClassLoader$1.run(URLClassLoader.java:217) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:205) at java.lang.ClassLoader.loadClass(ClassLoader.java:321) at java.lang.ClassLoader.loadClass(ClassLoader.java:266) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:264) at sun.rmi.server.LoaderHandler.loadProxyInterfaces(LoaderHandler.java:728) at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:672) at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:609) at java.rmi.server.RMIClassLoader$2.loadProxyClass(RMIClassLoader.java:646) at java.rmi.server.RMIClassLoader.loadProxyClass(RMIClassLoader.java:311) at sun.rmi.server.MarshalInputStream.resolveProxyClass(MarshalInputStream.java:255) at java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1548) at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1510) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1749) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1346) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:368) ... 12 more

Rispondi quotando

