我正在编写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() { }
}
我在做什么错了?