java.lang.NoClassDefFoundError after build Success in maven - java

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.

Related

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 ?
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.

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.

JavaMail ClassNotFoundException

I am trying to send an email from a Java Application but whenever I run the code found online here
When I run the code I receive this error:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/MessagingException
at nameInProgress.Driver.main(Driver.java:69)
Caused by: java.lang.ClassNotFoundException: javax.mail.MessagingException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 1 more
I'm pretty sure that the problem is relating to how I have attached the source (I am not using maven), I have viewed some other solutions on here, the highest suggests attaching a source code zip, but the link to that file is no longer valid and I cannot find it on my own.
EDIT: I have created a build path to JavaMail but I am still receiving this error.
As you stated, you don't have the javax mail jar/dependency. If you aren't using a dependency manager then you'll need to get the jar and add it to your classpath. I found a link for the jar here.

ClassNotFoundException: org.json.JSONException

I get the below exception even after having json.jar and commons-collections.jar in classpath. It fails exactly at the import statement for JSONException
Caused by: java.lang.ClassNotFoundException: org.json.JSONException
at java.net.URLClassLoader.findClass(URLClassLoader.java:434)
at com.ibm.ws.bootstrap.ExtClassLoader.findClass(ExtClassLoader.java:191)
at java.lang.ClassLoader.loadClass(ClassLoader.java:660)
at com.ibm.ws.bootstrap.ExtClassLoader.loadClass(ExtClassLoader.java:111)
at java.lang.ClassLoader.loadClass(ClassLoader.java:626)
at com.ibm.ws.classloader.ProtectionClassLoader.loadClass(ProtectionClassLoader.java:62)
at com.ibm.ws.classloader.ProtectionClassLoader.loadClass(ProtectionClassLoader.java:58)
at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java:509)
at java.lang.ClassLoader.loadClass(ClassLoader.java:626)
... 30 more
That looks like a runtime error, not a compile error, so the build path probably doesn't help you. Do you have those jars in your classpath? That's what's used at runtime to find classes.
Put your JAR libraries into the WEB-INF/lib folder.

Categories

Resources