java.lang.NoClassDefFoundError on Docker - java

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 ?

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.

Related

Javaagent throwing java.lang.NoClassDefFoundError: java/sql/PreparedStatement with java 15

Java agent is throwing this error when running with a java 15 app, if anybody can shed a light on why this might be coming, it will be very helpful.
java.lang.NoClassDefFoundError: java/sql/PreparedStatement
at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3325)
at java.base/java.lang.Class.getDeclaredMethods(Class.java:2466)
.
.
.
.
.
Caused by: java.lang.ClassNotFoundException: java.sql.PreparedStatement
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:435)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 19 more
Class not found Exception happens when JVM Doesn't find the class files on the classpath. Either the auto deployment feature(auto-deployment="true") is erroneous or you don't have class file(sql jar) on the classpath. If you are using Maven, Just check if sql jar(prepared statement class file and sql jar file) is on the classpath. If class file not on classpath, Just add the class file manually on classpath. It should resolve the error.
It means java.sql.PreparedStatement is available at compile time but not available at Runtime.
To solve the issue add the sql jar to classpath, if you are using maven add dependency in pom.xml.

ClassNotFoundException: com.azure.storage.common.policy.RequestRetryOptions

I am trying to run a java program that sends and receives messages to and from Azure Storage Queues; however, I keep getting the following ClassNotFoundException at runtime. I am having a hard time finding the jars necessary to fix it. Nothing I have found so far actually solves the problem.
Exception in thread "main" java.lang.NoClassDefFoundError: com/azure/storage/common/policy/RequestRetryOptions
at com.azure.storage.queue.QueueServiceClientBuilder.<init>(QueueServiceClientBuilder.java:83)
at com.cloudproject.azure.Connector.initiateConnection(Connector.java:58)
at com.cloudproject.server.ConnectionServer.main(ConnectionServer.java:30)
Caused by: java.lang.ClassNotFoundException: com.azure.storage.common.policy.RequestRetryOptions
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 3 more
I am not using maven in the build process, though I have pulled several jars from the maven repository - none of which have helped.
This seems to have been fixed by including the azure-storage-common jar, which I pulled from here. Not sure how I overlooked this one earlier.

Failure while deploying EAR file on Jboss Wildfly

I've got an EAR file which contains two wars and multiple jars. I'm using maven-ear-plugin to generate this file.
All jars are added in lib. There are few local jars and I'm adding them directly under EAR file. I've 2 local jars with a different name but contains the same package say abc.jar and xyz.jar
When I deploy this file on server I get following error:
"{\"WFLYCTL0080: Failed services\" => {\"jboss.mbean.service.publish:service=StreamReceiverStartup.start\" => \"org.jboss.msc.service.StartException in service jboss.mbean.service.publish:service=StreamReceiverStartup.start: WFLYSAR0001: Failed to execute legacy service start() method
Caused by: java.lang.reflect.InvocationTargetException
Caused by: java.lang.NoClassDefFoundError: <package_name>/<class_file>
Caused by: java.lang.ClassNotFoundException: <class_file> from [Module \\\"deployment.<ear_file_name>.ear.<jar_name>.jar:main\\\" from Service Module Loader]\"}}"
It's trying to detect from abc.jar instead xyz.jar which contains .
How to resolve this conflict? I tried removing one of the jar files. It results in the same exception but for a different class file, so I cannot discard any of these jars.
This is fixed by removing jars from application.xml

org.apache.cxf.bus.extension.ExtensionException in WAS9 server

Can you please help me with following error I'm facing in WAS9 environment:
In order to resolve the import
org.apache.cxf.binding.soap.SoapHeader
I added the following dependencies in my pom.xml:
cxf-api-2.7.7
cxf-rt-bindings-soap-2.7.7
But when I'm trying to run my application, I'm getting the following error.
Default Executor-thread-7] ([ ]) Controllerclass - org.apache.cxf.bus.extension.ExtensionException
at org.apache.cxf.bus.extension.Extension.load(Extension.java:222)
at org.apache.cxf.bus.extension.ExtensionManagerImpl.loadAndRegister(ExtensionManagerImpl.java:199)
at org.apache.cxf.bus.extension.ExtensionManagerImpl.initialize(ExtensionManagerImpl.java:118)
at org.apache.cxf.bus.extension.ExtensionManagerBus.doInitializeInternal(ExtensionManagerBus.java:147)
at org.apache.cxf.bus.CXFBusImpl.initialize(CXFBusImpl.java:191)
at com.ibm.ws.jaxws.bus.LibertyApplicationBusFactory.createBus(LibertyApplicationBusFactory.java:119)
at com.ibm.ws.jaxws.bus.LibertyApplicationBusFactory.createClientScopedBus(LibertyApplicationBusFactory.java:86)
at com.ibm.ws.jaxws.metadata.JaxWsClientMetaData.<init>(JaxWsClientMetaData.java:28)
at com.ibm.ws.jaxws.metadata.JaxWsModuleMetaData.getClientMetaData(JaxWsModuleMetaData.java:123)
at com.ibm.ws.jaxws.support.JaxWsMetaDataManager.getJaxWsClientMetaData(JaxWsMetaDataManager.java:84)
at com.ibm.ws.jaxws.support.JaxWsMetaDataManager.getJaxWsClientMetaData(JaxWsMetaDataManager.java:123)
at com.ibm.ws.jaxws.client.LibertyProviderImpl.createServiceDelegate(LibertyProviderImpl.java:56)
at javax.xml.ws.Service.<init>(Service.java:57)
Caused by: java.lang.InstantiationException:org.apache.cxf.bus.osgi.OSGIBusListener
at java.lang.Class.newInstance(Class.java:427)
at org.apache.cxf.bus.extension.Extension.load(Extension.java:218)
Caused by: java.lang.NoSuchMethodException:org.apache.cxf.bus.osgi.OSGIBusListener.<init>()
at java.lang.Class.getConstructor0(Class.java:3082)
at java.lang.Class.newInstance(Class.java:412)
The server where your WAS9 has been deployed has different version of the above jar file. You need to have same version of jar files both in your eclipse where you have developed your codes and the server where you are deploying the war or ear.
mavan dependency file pom.xml is used during your project compilation. It might add the jar in your binary under lib folder as well. But WAS9 might considering the one which is in server's CLASSPATH. Hence check your class path and replace that jar with the one which you have mentioned in your pom.xml file. Hope that will fix your issue.
We can eliminate this exception by adding webProfile-7.0 in our server.xml, but how ever this is not working with javaee-7.0 not sure, if one knows about how to handle this in javaee-7.0 please share your approach.

java.lang.NoClassDefFoundError after build Success in maven

Application Build got successful but getting the following error :
Exception in thread "Thread-29" java.lang.NoClassDefFoundError: org/apache/hadoop/util/ShutdownHookManager$2
at org.apache.hadoop.util.ShutdownHookManager.getShutdownHooksInOrder(ShutdownHookManager.java:124)
at org.apache.hadoop.util.ShutdownHookManager$1.run(ShutdownHookManager.java:52)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.util.ShutdownHookManager$2
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
... 2 more
I added this hadoop-common jar which has this class in pom file, classpath or any possible way i knew and could google but nothing worked.
It looks like a runtime problem. What I understand is that ClassRealm is trying to load a class at runtime and that class is not present in the jar. Just give it a look to the SelfFirstStrategy.java:50 and check if the class that is trying to be loaded actually exists.

Categories

Resources