我想一些非常基本的RMI:Java RMI InitialContext:等效於LocateRegistry.createRegistry(int)?
// Context namingContext = new InitialContext();
Registry reg = LocateRegistry.createRegistry(9999);
for (int i = 0; i < objs.length; i++) {
int id = objs[i].getID();
// namingContext.bind("rmi:CustomObj" + id , objs[i]);
reg.bind("CustomObj" + id , objs[i]);
}
即順利工作,但對未來而言,我需要使用InitialContext
。
Context namingContext = new InitialContext();
for (int i = 0; i < objs.length; i++) {
int id = objs[i].getID();
namingContext.bind("rmi:CustomObj" + id , objs[i]);
}
但我無法得到這個工作。我從命令行啓動了rmiregistry
。有沒有相當於LocateRegistry.createRegistry(int)
?或者以其他方式啓動InitialContext
從我的課堂使用的RMI註冊表/註冊表?
(而不是命令行的)堆棧跟蹤:
javax.naming.CommunicationException [Root exception is java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: bguiz.scratch.network.eg.Student]
at com.sun.jndi.rmi.registry.RegistryContext.bind(RegistryContext.java:126)
at com.sun.jndi.toolkit.url.GenericURLContext.bind(GenericURLContext.java:208)
at javax.naming.InitialContext.bind(InitialContext.java:400)
at bguiz.scratch.RMITest.main(RMITest.java:29)
Caused by: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: bguiz.scratch.CustomObj
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:396)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:250)
....(truncated)
編輯:我會刪除我自己的問題在一兩天的,因爲似乎沒有回答這個(我自己無法弄清楚)。最後呼籲任何咬人!
@EJP我已經添加了堆棧跟蹤到我的問題。另外,這個類將在服務器上運行 - 因此不需要指定URL(它將是本地主機)。客戶端需要指定URL,並且由於我在同一臺機器上進行了沙箱處理,所以它指定了「rmi:// localhost:1099 /」',但是我還沒有那麼遠,因爲這個類無法運行。 – bguiz 2010-03-10 10:02:29