gpt4 book ai didi

java - RMI远程异常: java. lang.ClassNotFoundException

转载 作者:行者123 更新时间:2023-12-02 03:35:34 26 4
gpt4 key购买 nike

我有一个简单的 RMI 服务器,它将文件存储在映射中并在请求时返回它们。 map 中存储的文件类型为Object。我已经这样做了,所以我不需要将库与包含存储的特定文件的项目的其他部分一起导入(还有其他方法吗?)。

既然存储的类型是Object,我不应该导入就可以吗?同时出现错误,我遇到 java Finalizer thread crash 。这是堆栈:

java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: util.MyClass (no security manager: RMI class loader disabled)
Invalid memory access of location 0x0 rip=0x7fff91016390 <<< this is from crash
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:334)
at sun.rmi.transport.Transport$1.run(Transport.java:159)
at java.security.AccessController.doPrivileged(Native Method)

这里还有来自客户端的一些代码:

public void uploadProjects(List<MyClass> projects) {
try {
Object obj = projects;
rmiServer.upload(channel, obj); // <<<< exception on this line
} catch (RemoteException ex) {
Logger.getLogger(RMIClient.class.getName()).log(Level.SEVERE, null, ex);
}
}

这是接口(interface)方法:

void upload(String channel, Object projects) throws RemoteException;

我在那里做错了什么吗?难道它不应该在不需要导入特定类的情况下与对象一起正常工作吗?我过去也尝试过使用安全管理器,但它只会导致更多麻烦,并且必须执行 AllPermissions 才能使其工作(在其他项目上)...

崩溃并不总是发生,但一定是由 RMI 引起的。

最佳答案

存储在 Map 中的对象的类型是您放入其中的任何类型,并且客户端必须可以通过其 CLASSPATH 访问该类型。

关于java - RMI远程异常: java. lang.ClassNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10035785/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com