我正在从 Oracle JDK8 迁移到 OpenJDK11。我在调用 exportObject(new Myobj) 时遇到问题。
由于在 jdk11 中删除了 rmi,我使用 glassfish jar 来使用 PortableRemoteObject 来导出和查找远程对象
我正在使用下面来自 glassfish 的罐子来获取 openjdk11 中缺少的类。
我期待 javax.rmi.PortableRemoteObject.PortableRemoteObject.exportObject() 像在 JDK8 中一样工作。但是我遇到了以下错误。我尝试使用来自 glassfish 罐子的 com.sun.corba.ee.impl.javax.rmi.PortableRemoteObjet 和 com.sun.corba.se.impl.javax.rmi.PortableRemoteObject。但仍然面临同样的错误。
java.rmi.NoSuchObjectException:对象未在 com.sun.corba.ee.impl.javax.rmi.PortableRemoteObject.toStub(MyClass.java:18) at javax.rmi.PortableRemoteObject.toStub(PortableRemoteObject.java:132) 中导出
RMIC 的 Ant 任务
<!-- Ant task for RMIC -->
<target name="rmic">
<taskdef name="rmic"
classname="org.apache.tools.ant.taskdefs.Rmic" />
<rmic classname="com.MyRmiImpl"
base="${classes.dir}"
classpathref="javac.classpath" />
</target>
公开课 MyNode {
static Registry registry;
public static void main(String[] args) {
try {
registry = LocateRegistry.createRegistry(3322);
MyRmiImpl remoteImpl = new MyRmiImpl();
PortableRemoteObject.exportObject(remoteImpl);
Remote objStub = PortableRemoteObject.toStub(remoteImpl);// getting exception at this line
registry.rebind("MyRmiInterface", objStub);
} catch (Exception e) {
e.printStackTrace();
}
}
}