我正在编写一个 Iiop 服务器,当我尝试运行它时遇到以下错误:
Exception in thread "main" javax.naming.ConfigurationException: Problem with PortableRemoteObject.toStub(); object not exported or stub not found [Root exception is java.rmi.NoSuchObjectException: object not exported]
at com.sun.jndi.toolkit.corba.CorbaUtils.remoteToCorba(CorbaUtils.java:105)
at com.sun.jndi.cosnaming.RemoteToCorba.getStateToBind(RemoteToCorba.java:79)
at javax.naming.spi.NamingManager.getStateToBind(NamingManager.java:870)
at com.sun.jndi.cosnaming.CNCtx.callBindOrRebind(CNCtx.java:600)
at com.sun.jndi.cosnaming.CNCtx.rebind(CNCtx.java:713)
at com.sun.jndi.cosnaming.CNCtx.rebind(CNCtx.java:730)
at javax.naming.InitialContext.rebind(InitialContext.java:433)
at ExecRmiIiopServ.<init>(ExecRmiIiopServ.java:13)
at ExecRmiIiopServ.main(ExecRmiIiopServ.java:20)
Caused by: java.rmi.NoSuchObjectException: object not exported
at sun.rmi.transport.ObjectTable.getStub(ObjectTable.java:124)
at java.rmi.server.RemoteObject.toStub(RemoteObject.java:106)
at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.toStub(PortableRemoteObject.java:156)
at javax.rmi.PortableRemoteObject.toStub(PortableRemoteObject.java:116)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.jndi.toolkit.corba.CorbaUtils.remoteToCorba(CorbaUtils.java:99)
... 8 more
根据我所读到的有关此错误的信息,我需要一个对象的强类型声明,以便垃圾收集器不会丢弃它,因此为什么我尝试添加一个函数对象来执行此操作,但错误仍然存在,两者在正常运行和断点的情况下,在 ctx.rebind 行触发错误。
public class ExecRmiIiopServ {
public ExecRmiIiopServ(String host, String port, String nume) throws Exception {
Runtime.getRuntime().exec("cmd /c start orbd -ORBInitialPort 1050");
Properties props = new Properties();
props.setProperty("java.naming.factory.initial", "com.sun.jndi.cosnaming.CNCtxFactory");
props.setProperty("java.naming.provider.url", "iiop://" + host + ":" + port);
ExecRmiInte functions = new ExecRmiImpl();
Context ctx = new InitialContext(props);
ctx.rebind(nume, functions);
System.out.println("Java RMI IIOP waiting: " + host + ":" + port + "/" + nume);
}
public static void main(String args[]) throws Exception {
if (args.length > 2)
new ExecRmiIiopServ(args[0], args[1], args[2]);
else
new ExecRmiIiopServ("localhost", "1050", "ExecIiop");
}
}
ExecRmiImpl() 类现在是这样的:
public class ExecRmiImpl implements ExecRmiInte {
public ExecRmiImpl() { }
}
我究竟做错了什么?