java.rmi.ServerException:服务器线程中发生RemoteException; ClassNotFoundException的

时间:2012-09-26 08:37:22

标签: java rmi

当我通过eclipse运行我的服务器代码时,我得到以下异常:

java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
    java.lang.ClassNotFoundException: com.RMIInterface
    at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:413)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:267)
    at sun.rmi.transport.Transport$1.run(Transport.java:177)

我已经通过在cmd行中输入“start rmiregistry”来启动RMI注册表。打开一个新窗口,标题为“c:\ Program Files \ Java \ jdk1.7.0 \ bin \ rmiregistry.exe”。在这条路径中我只有JDK。

此路径中提供的所有.class文件:D:\ Workspace \ Study \ bin \ com。

在com文件夹下,我有三个文件“RMIInterface,RMIServer,RMIClient”。

当我从eclipse运行Server代码时,我得到了一个上面提到的异常。(即,)找不到RMIInterface。但我把它放在同一个文件夹中。

我还应该怎样做才能运行服务器?

这是我的服务器代码:

RMIServer serRef = new RMIServer();
try {
    RMIInterface inref = (RMIInterface)UnicastRemoteObject.exportObject(serRef, 0);
    Registry reg = LocateRegistry.getRegistry();
    reg.bind("ServerObj", inref); -------->Exception in this line
} catch (AlreadyBoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

2 个答案:

答案 0 :(得分:1)

我认为问题在于您访问界面的方式。

如你所说,Under the com folder I have all three files "RMIInterface, RMIServer,RMIClient".

如果您的所有文件都在同一个包/文件夹中,那么为什么要编写com.RMIInterface

它应该只是RMIInterface,因为您提到它的方式会在您当前的com包中搜索另一个名为com的包。

我希望你明白我的观点。

修改

在运行RMI程序时,我们需要运行rmiregistry。

您应该在启动服务器程序之前运行rmiregistry

尝试在Windows中从控制台或CMD运行它。

在CMD中尝试rmiregistrystart rmiregistry。从CMD运行时,我们需要从运行javacjava的相同文件夹/包启动rmiregistry。在eclipse的情况下,我猜你应该尝试从你的com文件夹运行rmiregistry。

<强>更新

我认为现在你正试图从com文件夹中启动rmiregistry。只是尝试从你的com文件夹中启动它。

尽管如此 D:\Workspace\Study\bin\com>start rmiregistry

D:\Workspace\Study\bin\start rmiregistry

答案 1 :(得分:1)

Remote Server Error:RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: mathInterface

要执行以下步骤,该错误非常简单:

  • 例如,您的java文件考虑D驱动器
  • 启动rmiregistry D驱动器(例如D:\ start rmiregistry)然后不要在其他驱动器上启动rmiregistry,它将产生上述错误

(无论您的文件在哪里,请启动rmiregistry

参考:java.rmi.ServerException: RemoteException occurred in server thread (ClassNotFoundException)