我有JGroups的一个问题,即建立我的项目,运行后它会产生这样的错误:ClassNotFoundException的用的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运行时明确设置classpath中。但是,在运行代码时,它似乎仍然不会调用getState()
和setState()
方法,因为没有打印语句。 SimpleChat
不打印received state...
喜欢它的意思。
有没有人有解决方案?
最好。