我想一些非常基本的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