title: Error Initializing Kafka Producer with Avro Serializer: java.lang.NoClassDefFoundError
body: <p>I'm having trouble getting a KafkaProducer instantiation to accept an avro serializer for the value serializer config property. I installed <code>kafka-avro-serializer-5.2.2.jar</code> with </p>
  
  <pre><code>mvn install:install-file -DgroupId=io.confluent -DartifactId=kafka-avro-serializer \
      -Dversion=5.2.2 -Dpackaging=jar -Dfile=C:/Users/myuser/Downloads/kafka-avro-serializer-5.2.2.jar
  </code></pre>
  
  <p>The jar and related files were added to <code>~\.m2\repository\io\confluent\kafka-avro-serializer\5.2.2</code>. I then added the following to my project POM file within dependencies:</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;io.confluent&lt;/groupId&gt;
      &lt;artifactId&gt;kafka-avro-serializer&lt;/artifactId&gt;
      &lt;version&gt;5.2.2&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>Then the following imports in my client work fine; code compiles</p>
  
  <pre><code>import io.confluent.kafka.serializers.KafkaAvroSerializer;
  import org.apache.kafka.clients.producer.KafkaProducer;
  import org.apache.kafka.clients.producer.Producer;
  import org.apache.kafka.clients.producer.ProducerConfig;
  </code></pre>
  
  <p>But running this:</p>
  
  <pre><code>Properties props = new Properties();
  props.put("bootstrap.servers", "localhost:9092");
  props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
  props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, KafkaAvroSerializer.class.getName());
  
  final Producer&lt;String, Object&gt; producer = new KafkaProducer&lt;&gt;(props);
  </code></pre>
  
  <p>Results in error:</p>
  
  <pre><code>Exception in thread "main" java.lang.NoClassDefFoundError: io/confluent/common/config/ConfigException
  </code></pre>
  
  <p>I found a similar issue tracked <a href="https://github.com/confluentinc/kafka-connect-hdfs/issues/318" rel="nofollow noreferrer">here</a>. But I'm not using Kafka Connect. Also </p>