2017年9月6日 | Leave a comment 问题: rmi registry.bind exception Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: java.lang.ClassNotFoundException: rmi1.api.Exchange at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source) 123 Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: java.lang.ClassNotFoundException: rmi1.api.Exchange at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source) package rmi1.server; import java.io.IOException; import java.rmi.AccessException; import java.rmi.AlreadyBoundException; import java.rmi.RemoteException; import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; import java.rmi.server.UnicastRemoteObject; import java.util.logging.Level; import java.util.logging.Logger; import javax.naming.NamingException; import rmi1.api.Exchange; /** * * @author sihai */ public class App { private static final Logger LOG = Logger.getLogger(App.class.getName()); public static void main(String[] argv) throws NamingException, RemoteException, IOException{ Exchange ex = (Exchange) UnicastRemoteObject.exportObject(new HuobiExchange(),0); Registry reg = LocateRegistry.getRegistry(); try { reg.bind("exchange", ex); } catch (AlreadyBoundException | AccessException ex1) { LOG.log(Level.SEVERE, null, ex1); } System.out.println("wait connet"); System.in.read(); } } 12345678910111213141516171819202122232425262728293031323334 package rmi1.server; import java.io.IOException;import java.rmi.AccessException;import java.rmi.AlreadyBoundException;import java.rmi.RemoteException;import java.rmi.registry.LocateRegistry;import java.rmi.registry.Registry;import java.rmi.server.UnicastRemoteObject;import java.util.logging.Level;import java.util.logging.Logger;import javax.naming.NamingException;import rmi1.api.Exchange; /** * * @author sihai */public class App { private static final Logger LOG = Logger.getLogger(App.class.getName()); public static void main(String[] argv) throws NamingException, RemoteException, IOException{ Exchange ex = (Exchange) UnicastRemoteObject.exportObject(new HuobiExchange(),0); Registry reg = LocateRegistry.getRegistry(); try { reg.bind("exchange", ex); } catch (AlreadyBoundException | AccessException ex1) { LOG.log(Level.SEVERE, null, ex1); } System.out.println("wait connet"); System.in.read(); }} 解决: 运行时指定 java.rmi.server.codebase & java.rmi.server.useCodebaseOnly=false java -cp rmi1-server-1.0.jar:rmi1-api-1.0.jar -Djava.rmi.server.codebase=file:///Users/sihai/Documents/demo/java/rmi1/rmi1-api/target/classes/ -Djava.rmi.server.useCodebaseOnly=false rmi1.server.App 1 java -cp rmi1-server-1.0.jar:rmi1-api-1.0.jar -Djava.rmi.server.codebase=file:///Users/sihai/Documents/demo/java/rmi1/rmi1-api/target/classes/ -Djava.rmi.server.useCodebaseOnly=false rmi1.server.App 参考: https://github.com/giant35/rmi1 http://docs.oracle.com/javase/7/docs/technotes/guides/rmi/enhancements-7.html http://docs.oracle.com/javase/6/docs/technotes/guides/rmi/hello/hello-world.html