【发布时间】: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.Channel 和 org.jgroups.Channel(以及其他)。
JGroup 开发人员提供了一个SimpleChat 程序,但是当我为此创建一个新项目时遇到了同样的问题。
编辑
事实证明,当从 CLI 运行时,我必须明确设置类路径。但是,在运行代码时,似乎永远不会调用 getState() 和 setState() 方法,因为没有打印语句。 SimpleChat 不会像预期的那样打印 received state...。
有人有解决办法吗?
最好的。
【问题讨论】: