title: Why does Kafka consumer throw "java.lang.NoClassDefFoundError: kafka/consumer/ConsumerConfig" at startup?
body: <p>I am trying out the basic consumer code from example given in apache website. Compilation is fine. But I am getting ClassNotFoundException while running using the command <code>java -jar target/JarName.jar</code>:</p>
  
  <pre><code>Exception in thread "main" java.lang.NoClassDefFoundError: kafka/consumer/ConsumerConfig
      at com.package.ConsumerClass.functionConsumer(ConsumerClass.java:41)
      at com.package.App.main(App.java:26)
  Caused by: java.lang.ClassNotFoundException: kafka.consumer.ConsumerConfig
      at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
  </code></pre>
  
  <p>The source code is </p>
  
  <pre><code>package com.package;
  import java.util.HashMap;
  import java.util.Properties;
  import java.util.Map;
  import java.util.List;
  import java.lang.Object;
  import kafka.consumer.Consumer;
  import kafka.consumer.ConsumerConfig;
  import kafka.consumer.ConsumerConnector;
  import kafka.consumer.ConsumerIterator;
  import kafka.consumer.KafkaStream;
  public class ExampleConsumer {
      public void exampleConsumer(){
          Properties props = new Properties();
          props.put("zk.connect", "localhost:2181");
          props.put("zk.connectiontimeout.ms", "1000000");
          props.put("groupid", "test_group");
  
          ConsumerConfig consumerConfig = new ConsumerConfig(props);
          ConsumerConnector consumerConnector = (ConsumerConnector) Consumer.createJavaConsumerConnector(consumerConfig);
  
          Map&lt;String, Object&gt; topicCountMap = new HashMap&lt;String, Object&gt;();
          topicCountMap.put("test", new Integer(1));
          Map&lt;String, List&lt;KafkaStream&lt;byte[], byte[]&gt;&gt;&gt; consumerMap = (Map&lt;String, List&lt;KafkaStream&lt;byte[], byte[]&gt;&gt;&gt;) consumerConnector.createMessageStreams((scala.collection.Map&lt;String, Object&gt;) topicCountMap);
          KafkaStream&lt;byte[], byte[]&gt; stream = consumerMap.get("test").get(0);
          ConsumerIterator&lt;byte[], byte[]&gt; it = stream.iterator();
          while(it.hasNext())
              System.out.println(new String(it.next().message()));
      }
  }
  </code></pre>
  
  <p>I am using Maven for dependency resolution. The dependency part of the pom.xml looks like this</p>
  
  <pre><code>&lt;dependency&gt;
          &lt;groupId&gt;org.apache.kafka&lt;/groupId&gt;
          &lt;artifactId&gt;kafka_2.10&lt;/artifactId&gt;
          &lt;version&gt;0.8.2.1&lt;/version&gt;
          &lt;scope&gt;compile&lt;/scope&gt;
  &lt;/dependency&gt;
          &lt;dependency&gt;
                  &lt;groupId&gt;org.apache.kafka&lt;/groupId&gt;     
                  &lt;artifactId&gt;kafka-clients&lt;/artifactId&gt;
                  &lt;version&gt;0.8.2.1&lt;/version&gt;
                  &lt;scope&gt;compile&lt;/scope&gt;
          &lt;/dependency&gt;
  </code></pre>
  
  <p>I am using kafka_2.10-0.8.2.1 version. Any suggestion is welcome.</p>