我的 RMI 客户端在尝试运行服务器方法时收到 Log4j 的 NoClassDefFoundErrors

发布于 2024-10-01 13:40:33 字数 417 浏览 2 评论 0原文

我一直在互联网上搜索,但我找不到一种方法让 RMI 代码按照我想要的方式运行(如 RPC 调用)。

Java:1.5

我正在尝试设置客户端/服务器 RMI 调用 - 客户端应该调用服务器上的“square()”方法,服务器对传递的数字进行平方,然后返回它。

在构建此过程的过程中,我在服务器方法上放置了 log4j 语句。

当我尝试从命令行运行客户端时,我在 RMI 注册表中查找名称,在本地实例上执行 square() 方法,并在客户端上尝试运行 log4j 时收到“NoClassDefFoundError” square() 方法。

这告诉我客户端不仅尝试下载接口,还尝试下载服务器逻辑的实现。对于我目前的情况来说,这不是我想要的。

我查了又查,对于如何让系统远程运行这些方法(例如 RPC 调用)找不到明显的答案。

I have been searching all over the Internet, but I can't find a way to get the RMI code to behave the way I want (like an RPC call).

Java: 1.5

I am trying to set up a client/server RMI call - the client should call the "square()" method on the server, the server squares the number that's passed, and returns it.

During the process of building this, I put a log4j statement on the server method.

When I try to run the client from the command line, I look up the name in the RMI registry, execute the square() method on the local instance, and get a "NoClassDefFoundError" for log4j on the client as it attempts to run the square() method.

What this is telling me is that the client is attempting to download not only the interface, but the implementation of the server logic as well. Which, for the situation I'm in, is not what I want.

I've looked and looked, and I can't find an obvious answer for how I should get the system to run the methods remotely, like an RPC call.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

囚你心 2024-10-08 13:40:33

或者它可能会告诉您,它正在将异常编组回客户端,以便您查看是否(试图假装网络边界不存在)

square();,有效吗?

另外,如果您让服务器在本地调用它的 square() 方法(例如,当您的服务器进程启动时),这是否有效? - 这将告诉您 log4j 调用堆栈中的某个位置是否缺少 jar 依赖项。

or it could be telling you that it's marshalling the exception back to the client for you to see if (trying to pretend that the network boundary isn't there)

if you remove the log4j call from the square();, does it work?

also if you make the server call it's square() method locally (e.g when your server proces starts up) does this work? - this will tell you if you are missing a jar dependency somewhere in the log4j call stack.

醉生梦死 2024-10-08 13:40:33

出现 NoClassDefFoundError 错误的原因是 JVM/ClassLoader 正在尝试创建类的新实例,但未找到该类的定义。

确保 RMI 服务器中存在 log4j.jarlog4j-xxxx.jar(其中 xxxx 是 log4j 版本)客户端。编译您的项目并构建它以将 log4j.jar 包含在其中。

The reason why you're having NoClassDefFoundError Error is because the JVM/ClassLoader is trying to create a new instance of a class but the definition of the class is not found.

Make sure that the log4j.jar or log4j-x.x.xx.jar (where x.x.xx is the log4j version) exists in your RMI server and client. Compile your project and build it to include the log4j.jar inside it.

只怪假的太真实 2024-10-08 13:40:33

我发现了问题 - 我的服务器实现没有扩展 UnicastRemoteObject。显然,这会导致 RMI 服务器逻辑向客户端发送服务器实现代码的副本,而不是服务器实现代码的存根表示。

I discovered the problem - my server implementation was not extending UnicastRemoteObject. Apparently this causes the RMI server logic to send the client a copy of the server implementation code, instead of a stub representation of the server implementation code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文