2013-12-10 21 views
0

我有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.Channelorg.jgroups.Channel(以及其他)正在被发现。

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

编辑

因此,原来我已经从CLI运行时明确设置classpath中。但是,在运行代码时,它似乎仍然不会调用getState()setState()方法,因为没有打印语句。 SimpleChat不打印received state...喜欢它的意思。

有没有人有解决方案?

最好。

回答

0

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