JavaRMI InitialContext:等同于LocaterRegistry.createRegistry(int)?
我正在尝试一些非常基本的RMI:JavaRMI InitialContext:等同于LocaterRegistry.createRegistry(int)?,java,registry,rmi,initial-context,Java,Registry,Rmi,Initial Context,我正在尝试一些非常基本的RMI: // Context namingContext = new InitialContext(); Registry reg = LocateRegistry.createRegistry(9999); for ( int i = 0; i < objs.length; i++ ) { int id = objs[i].getID(); // namingContext.b
// 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] );
}
但我不能让它工作。我已经从命令行启动了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)
编辑:我将在几天后删除我自己的问题,因为这个问题似乎没有答案(我自己还没弄明白)。最后一次点名 是否存在与
LocateRegistry.createRegistry(int)
等效的文件
没有
或者以其他方式从类内部启动InitialContext使用的RMI注册表/注册表
仅LocateRegistry.createRegistry()
我几乎可以肯定,您需要在URL中指定主机名。您收到了什么异常和错误消息
java.lang.ClassNotFoundException: bguiz.scratch.network.eg.Student caused by
java.lang.ClassNotFoundException: bguiz.scratch.CustomObj
是否存在与LocateRegistry.createRegistry(int)
等效的文件
没有
或者以其他方式从类内部启动InitialContext使用的RMI注册表/注册表
仅LocateRegistry.createRegistry()
我几乎可以肯定,您需要在URL中指定主机名。您收到了什么异常和错误消息
java.lang.ClassNotFoundException: bguiz.scratch.network.eg.Student caused by
java.lang.ClassNotFoundException: bguiz.scratch.CustomObj
检查这门课是否可用
检查这个类是否可用?经过多次修补,我已经解决了这个问题。仅供参考,以下是它的内容: 由于RMI注册表有自己的类路径,因此引发了
ClassNotFoundException
。包含InitialContext
的类在其类路径上是否有自定义对象并不重要-必须初始化RMI注册表,以便自定义对象也在其类路径上
为此,在启动
rmiregistry
之前,在comman行上设置classpath
环境值。如果此类路径包含自定义对象的类,则不会抛出ClassNotFoundException
,随后将避免ServerException
和“CommunicationException”。经过多次修补,我解决了这个问题。仅供参考,以下是它的内容:
由于RMI注册表有自己的类路径,因此引发了ClassNotFoundException
。包含InitialContext
的类在其类路径上是否有自定义对象并不重要-必须初始化RMI注册表,以便自定义对象也在其类路径上
为此,在启动
rmiregistry
之前,在comman行上设置classpath
环境值。如果此类路径包含自定义对象的类,则不会抛出ClassNotFoundException
,随后将避免ServerException
和“CommunicationException”。@EJP我已将堆栈跟踪添加到我的问题中。此外,此类将在服务器上运行-因此无需指定URL(它将是本地主机)。客户端需要指定URL,因为我在同一台机器上进行沙箱处理,所以它指定了”rmi://localhost:1099/“
,但是我还没有做到这一点,因为这个类无法运行。@EJP我已经在我的问题中添加了堆栈跟踪。此外,此类将在服务器上运行-因此无需指定URL(它将是本地主机)。客户端需要指定URL,因为我在同一台机器上进行沙箱处理,所以它指定了”rmi://localhost:1099/“
,但是我还没有做到这一点,因为这个类无法运行。是的,它肯定是-这是我检查的第一件事情之一。事实上,数组objs[]
是一个CustomObj
s的数组,它被同一个类使用。我还验证了它是否在类路径上。是的,它绝对是-这是我检查的第一件事情之一。事实上,数组objs[]
是一个CustomObj
s的数组,它被同一个类使用。我还验证了它是否在类路径上。