title: Why can't java find my class?
body: <p>I have a class that compiles without error. The class has a main method. But when I try to run it on ubuntu linux from the classes' directory I get a class not found error. I am pretty sure I am missing something dead obvious but I don't see it.</p>
  
  <p>Here is my ls operation: </p>
  
  <pre><code>zookeeper@zookeeper-virtual-machine:~/zookeeper-3.4.5/programs$ ls
  CreateGroup.java  LsGroup.class  LsGroup.java  zookeeper-3.4.5.jar
  </code></pre>
  
  <p>Here is what happens when I to run LsGroup</p>
  
  <pre><code>zookeeper@zookeeper-virtual-machine:~/zookeeper-3.4.5/programs$ java -cp "zookeeper-3.4.5.jar" LsGroup
  Exception in thread "main" java.lang.NoClassDefFoundError: LsGroup
  Caused by: java.lang.ClassNotFoundException: LsGroup
      at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
  Could not find the main class: LsGroup. Program will exit.
  </code></pre>
  
  <p>Here is the code for LsGroup</p>
  
  <pre><code>package org.zookeeper;    
  import java.io.IOException;
  import java.util.List;
  import java.util.concurrent.CountDownLatch;
  
  import org.apache.zookeeper.KeeperException;
  import org.apache.zookeeper.WatchedEvent;
  import org.apache.zookeeper.Watcher;
  import org.apache.zookeeper.ZooKeeper;
  import org.apache.zookeeper.Watcher.Event.KeeperState;
  
  public class LsGroup implements Watcher {
  
      private static final int SESSION_TIMEOUT = 5000;
      private ZooKeeper zk;
      private CountDownLatch connectedSignal = new CountDownLatch(1);
  
      public void connect(String hosts) throws IOException, InterruptedException {
          zk = new ZooKeeper(hosts, SESSION_TIMEOUT, this);
          connectedSignal.await();
      }
  
      @Override
      public void process(WatchedEvent event) { // Watcher interface
          if (event.getState() == KeeperState.SyncConnected) {
              connectedSignal.countDown();
          }
      }
  
      public void ls(String groupName) throws KeeperException, InterruptedException {
          String path = "/" + groupName;
          try {
              List&lt;String&gt; children = zk.getChildren(path, false);
              for (String child : children) {
                  System.out.println(path+"/"+child);
                  System.out.println(zk.getChildren(path +"/"+ child, false));
              }
          } catch (KeeperException.NoNodeException e) {
              System.out.printf("Group %s does not exist\n", groupName);
              System.exit(1);
          }
      }
  
      public void close() throws InterruptedException {
          zk.close();
      }
  
      public static void main(String[] args) throws Exception {
          LsGroup lsGroup = new LsGroup();
          lsGroup.connect(args[0]);
          lsGroup.ls(args[1]);
          lsGroup.close();
      }
  }
  </code></pre>