nodef found org.apache.kafka.common.serialization.stringserializer

Exception when you are trying to deploy a Kafka Producer/Consumer application as a jar.

Problem

Example code Producer.java#L41

Here I defined the StringSerialized.class as a property for the Kafka Producer configuration.

This application is deployed as a jar to the Keycloak Server (SPI). The package is imported into the class. But, it failed to get resolved during the runtime.

The hacky solution is to reset the current thread context

Using Producer.java#L34

Thread.currentThread().setContextClassLoader(null);

isn’t recommended. Playing with classloader can cause unpredictable issues

Solution

<!-- Maven Assembly Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<finalName>Your-jar-name</finalName>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>

If still, you see the issue. Try adding

Class.forName("org.apache.kafka.common.serialization.stringserializer");

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store