问题:
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) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
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 |
参考:
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