当我通过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-rmigregistry"就可以启动RMI注册表。打开了一个标题为"c:\Program Files\Java\jdk1.7.0\bin\rmiregistry.exe"的新窗口。在这个路径中,只有JDK。
我的所有.class文件都在此路径中可用:D:\Workspace\Study\bin.com。
在com文件夹下,我有三个文件"RMInterface,RMIServer,RMIClient"。
当我从eclipse运行服务器代码时,我得到了上面提到的异常。(即)找不到RMInterface。但我把它放在同一个文件夹里。
我还应该做些什么来运行服务器?
这是我的服务器代码:
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();
}
我认为问题出在访问接口的方式上。
正如您所说,Under the com folder I have all three files "RMIInterface, RMIServer,RMIClient".
如果你的所有文件都在同一个包/文件夹中,那么你为什么要写com.RMIInterface
它应该只是RMIInterface
,因为您提到的方式会在当前的com
包中搜索另一个名为com
的包。
我希望你明白我的意思。
编辑
在运行RMI程序时,我们确实需要运行rmiregistry。
您应该在启动服务器程序之前运行rmiregistry
。
尝试从控制台或窗口中的CMD运行它。
尝试CMD中的rmiregistry
或start rmiregistry
。当从CMD运行时,我们确实需要从运行javac
和java
的同一文件夹/包启动rmiregistry。在eclipse的情况下,我想您应该尝试从您的com文件夹中运行rmiregistry。
更新
我认为现在你正试图从com文件夹中启动rmiregistry。试着从你的com文件夹中启动它。
D:WorkspaceStudybincom>start rmiregistry
尝试
D:WorkspaceStudybinstart rmiregistry
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-rmigregistry),然后不要在其他驱动器上启动rmiregistrate,这将产生上述错误
(无论文件在哪里,都要启动rmiregistry
)
引用:java.rmi.ServerException:服务器线程中发生RemoteException(ClassNotFoundException)