title: ClassNotFoundException with JGroups
body: <p>I have an issue with JGroups where after building my project, running it produces this error:</p>
  
  <p><code>Caused by: java.lang.ClassNotFoundException: org.jgroups.ReceiverAdapter</code></p>
  
  <p>My class looks something like this -</p>
  
  <pre><code>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");
      }
  }
  </code></pre>
  
  <p>Running the project from IntelliJ produces no errors, but does not produce the desired prints from <code>getState()</code> and <code>setState()</code> either. I tried creating a brand new project in the Eclipse IDE, but the same is happening there too. Connecting has been working fine, states is a new addition to my project.</p>
  
  <p>Running <code>java MyClass</code> from the command line fires the error seen at the start of this question.  The JGroups jar seems to be added to the classpath properly as <code>org.jgroups.Channel</code> and <code>org.jgroups.Channel</code> (among others) are being found.</p>
  
  <p>There is a <a href="http://www.jgroups.org/tutorial/code/SimpleChat.java" rel="nofollow">SimpleChat</a> program provided by the JGroup devs, but when I created a new project for this I encountered the same problem.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>So it turns out I have to explicitly set the classpath when running from the CLI. But still, when running the code it seems like the <code>getState()</code> and <code>setState()</code> methods are never called as there are no print statements. <code>SimpleChat</code> doesn't print <code>received state...</code> like it is meant to.</p>
  
  <p>Does anyone have a solution?</p>
  
  <p>Best.</p>