【问题标题】:ClassNotFoundException with JGroups带有 JGroups 的 ClassNotFoundException
【发布时间】:2013-12-10 21:00:43
【问题描述】:

我有一个 JGroups 问题,在构建我的项目后,运行它会产生以下错误:

Caused by: java.lang.ClassNotFoundException: org.jgroups.ReceiverAdapter

我的班级看起来像这样 -

import org.jgroups.ReceiverAdapter;
import org.jgroups.Channel;
import org.jgroups.JChannel;

public class MyClass extends ReceiverAdapter implements MyInterface {

    Channel channel;
    String state = "state";

    public MyClass() {
        super();
        start();
    }

    public void start() {
        try {
            channel = new JChannel();
            channel.setReceiver(this);
            channel.connect("ServerCluster");
            channel.getState(null, 0);
            System.out.println("Connected to cluster");
        } catch (Exception e) {
            System.out.println("Failed to connect to cluster");
        }
    }

    public void getState(OutputStream output) throws Exception {
        System.out.println("get response");
    }

    public void setState(InputStream input) throws Exception {
        System.out.println("set test");
    }
}

从 IntelliJ 运行项目不会产生错误,但也不会从 getState()setState() 产生所需的打印。我尝试在 Eclipse IDE 中创建一个全新的项目,但那里也发生了同样的事情。连接一直运行良好,状态是我项目的新成员。

从命令行运行 java MyClass 会触发在此问题开头看到的错误。 JGroups jar 似乎已正确添加到类路径中,因为正在找到 org.jgroups.Channelorg.jgroups.Channel(以及其他)。

JGroup 开发人员提供了一个SimpleChat 程序,但是当我为此创建一个新项目时遇到了同样的问题。

编辑

事实证明,当从 CLI 运行时,我必须明确设置类路径。但是,在运行代码时,似乎永远不会调用 getState()setState() 方法,因为没有打印语句。 SimpleChat 不会像预期的那样打印 received state...

有人有解决办法吗?

最好的。

【问题讨论】:

    标签: java classpath jgroups


    【解决方案1】:

    所以,我在 JChannel 上使用的是 RpcDispatcher,看来我不能在同一个频道上使用调度程序和 getState()setState() 方法。简单的解决方案:创建第二个频道。看来我缺乏对 JGroups 基础知识的了解!

    【讨论】:

      猜你喜欢
      • 2023-03-27
      • 2011-12-12
      • 2016-06-15
      • 1970-01-01
      • 2012-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多