我对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中创建一个全新的项目,但同样的情况也发生在那里。连接一直运行良好,状态是我的项目的一个新的补充。
从命令行运行java MyClass会触发在此问题开始时看到的错误。JGroups jar似乎被正确地添加到类路径中,因为org.jgroups.Channel和org.jgroups.Channel (以及其他)正在被找到。
有一个由SimpleChat开发人员提供的JGroup程序,但是当我为此创建一个新的项目时,我遇到了同样的问题。
编辑
因此,在从CLI运行时,我必须显式地设置类路径。但是,在运行代码时,getState()和setState()方法似乎从未被调用过,因为没有print语句。SimpleChat不像它想要的那样打印received state...。
有人有解决办法吗?
最好的。
发布于 2013-12-10 13:00:43
因此,我在JChannel上使用RpcDispatcher,似乎不能在同一个通道上使用dispatcher以及getState()和setState()方法。简单的解决方案:创建第二个通道。看来我对JGroups的基础知识很缺乏!
https://stackoverflow.com/questions/20485290
复制相似问题