'java.lang.NoClassDefFoundError on Docker
When The Program is Ran in the Local PC, it is working fine, but if it is running in the docker throws the following error:
Exception in thread "Thread-16" java.lang.NoClassDefFoundError: org/apache/kafka/common/serialization/Serializer
at org.eclipse.kura.example.configurable.ConfigurableExample$1.run(ConfigurableExample.java:52)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: org.apache.kafka.common.serialization.Serializer cannot be found by org.eclipse.kura.example.configurable_1.0.0.202201251713
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:484)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:395)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:387)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:150)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 2 more
But this is working fine in the LocalMachine. What is the issue ?
Solution 1:[1]
This may be debugged in following ways:
- Ensure that you have all the required dependencies inside your docker container. You may want to check your docker base image first.
- Check if you have set the classpath appropriately to include that jar file (kafka-clients).
- Validate your entrypoint/cmd which you use to start the service to check if it has the appropriate classpath.
- Check your classloader and see why it is not able to load that class.
- If your executable is a fat jar file, check if that jar file contains the kafka-clients library where that class is present.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | JavaTechnical |
