Top v Reasons of Exception inwards thread primary java.lang.NoClassDefFoundError inwards Java

NoClassDefFoundError inwards Java
The Exception inwards thread "main" java.lang.NoClassDefFoundError is a mutual mistake inwards Java which occurs if a ClassLoader is non able to uncovering a item cast inwards the classpath spell trying to charge it. The Exception inwards thread "main" suggests that this mistake has occurred inwards the principal thread, the thread which is responsible for running Java application. This mistake tin occur to whatever thread but if it happens inwards principal thread together with so your programme volition crash. As per Javadoc, NoClassDefFoundError can hold upward thrown during linking or loading of the cast file. It's denoted yesteryear java.lang.NoClassDefFoundError together with comes when that item cast is acquaint during compile fourth dimension but somehow non available during runtime. This could hold upward due to missing JAR file, whatever permission issue, or wrong classpath on runtime, depending upon your environment.


Java Programmers oft confuse betwixt java.lang.ClassNotFoundException and java.lang.NoClassDefFoundError in Java which is likewise related to cast loading inwards Java but at that spot is a slight departure betwixt NoClassDefFoundError together with ClassNotFoundException inwards Java, The ClassNotFoundException comes when Java tries to charge a cast yesteryear its binary cite during runtime together with Class is non available at that time. for example, when you lot charge JDBC driver using Class.forName(String classname), you lot volition acquire java.lang.ClassNotFoundException instead of NoClassDefFoundError.

On the other hand, NoClassDefFoundError comes when the cast was available at compile fourth dimension but somehow non available at runtime e.g. if static initializer block of a cast throws an Exception during loading, the cast volition non hold upward available for other's to use. If whatever cast examine to refer that cast together with so the classloader volition throw the java.lang.NoClassDefFoundError. If you lot like, you lot tin read to a greater extent than most their departure inwards this article.




5 mutual causes of  Exception inwards thread "main" java.lang.NoClassDefFoundErro in Java

The Exception inwards thread "main" java.lang.NoClassDefFoundError inwards Java tin come upward due to a diversity of reasons inwards Java, But most of the fourth dimension java.lang.NoClassDefFoundError comes due to CLASSPATH errors inwards Java. Influenza A virus subtype H5N1 right agreement of how classpath industrial plant inwards Java is required to troubleshoot together with solve the  Exception inwards thread "main" java.lang.NoClassDefFoundError in Java.

Anyway hither are roughly of the mutual argue which has caused  Exception inwards thread "main" java.lang.NoClassDefFoundError in diverse Java application inwards past, your employment could good hold upward due to whatever of these reasons. 

1) Missing JAR file inwards Classpath
The offender cast is non available inwards the classpath of your Java application. For example, if you lot are getting "Caused By: java.lang.NoClassDefFoundError: org/apache/log4j/Logger" mistake inwards your application which agency classloader of your application is non able to uncovering org.apache.log4j.Logger cast inwards its classpath. The simplest reasons of this mistake are the missing log4j.jar file inwards the classpath. As presently equally you lot add together that JAR into classpath the mistake goes away. See here to acquire to a greater extent than most troubleshooting this item issue.

Similarly, you lot powerfulness convey seen java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlObject which comes if you lot are using XMLbeans but xmlbeans-2.60.jar is non acquaint inwards your classpath (see here).


Another mutual 1 is java.lang.NoClassDefFoundError: org/dom4j/DocumentException, which comes due to missing dom4j.jar file (see here).

In short, the kickoff measurement to solving "Exception inwards thread "main" java.lang.NoClassDefFoundError" is to depository fiscal establishment tally if offender cast is available inwards classpath or not. In Eclipse, you lot tin role shortcuts similar search resources (Ctrl + R) or search type (Ctrl + T) to uncovering which JAR file that item cast belongs together with and so depository fiscal establishment tally if that JAR is available inwards classpath or not. See here to acquire to a greater extent than useful Eclipse shortcuts for Java developers.


2) Due to Visibility lawsuit betwixt multiple Classloaders
Sometimes inwards complex environments e.g. Java EE container, it's possible that the offender cases is available inwards classpath but non visible to the classLoader which is trying to charge that item class. For example, inwards Java classloader operate yesteryear delegation together with visibility. Influenza A virus subtype H5N1 cast loading asking is kickoff delegated to bring upward cast loader earlier modest fry cast loader attempts to charge it, therefore whatever cast loaded yesteryear bring upward cast loader is visible to modest fry cast loader but the contrary is non truthful i.e. a cast loaded yesteryear modest fry classloader is non visible to bring upward cast loader.

Suppose a cast is used yesteryear ii JAR files e.g. WAR together with EJB-JAR file but it acquaint inwards WAR file together with so it volition hold upward visible to spider web app classloader but non create the classloader which loads the cast from EJB-JAR file.


3) Missing classpath entry inwards Manifest file
You tin likewise acquire the "Exception inwards thread "main" java.lang.NoClassDefFoundError" if you lot are running your Java application using java -jar ascendancy together with that cast were non defined inwards manifest file's ClassPath attribute. In past, I convey spent hours to figure out which JAR is missing exclusively to uncovering that Java is using the classpath defined inwards the manifest file together with non the classpath surroundings variable.

is a mutual mistake inwards Java which occurs if a  Top five Reasons of Exception inwards thread principal java.lang.NoClassDefFoundError inwards Java

4) Environment Issues 
I convey seen foreign reasons of java.lang.NoClassDefFound mistake spell working inwards Java. In 1 instance 1 of the musical rhythm out scripts which was starting our Java application was overriding the value of here to acquire to a greater extent than most how to add together multiople JAR files inwards classpath.



5) Error inwards Static Initializer block
One of the most mutual reasons for "Exception inwards thread "main" java.lang.NoClassDefFoundError" is mistake inwards static initializer block.  This is the block of code which is declared using static keyword together with executed when a cast is loaded. If suppose cast Influenza A virus subtype H5N1 throw Exception from static initializer block together with cast B uses cast A. In that instance when cast B volition hold upward loaded it volition throw "Exception inwards thread "main" java.lang.NoClassDefFoundError" because it volition non hold upward able to uncovering it's dependency which is cast A. 

So side yesteryear side time, if you lot run into the NoClassDefFound mistake inwards your Java application, brand certain you lot search for static initializer mistake i.e. java.lang.ExceptionInInitializerError inwards your log file. That is the rootage drive of the NoClassDefFoundError you lot were seeing.


That's all on what is NoClassDefFoundError inwards Java together with what are the mutual argue which causes Exception inwards thread "main" java.lang.NoClassDefFoundError inwards Java. Most of the fourth dimension it's merely a missing JAR file which causes this employment but sometimes it tin hold upward a nightmare to solve e.g. inwards instance your application is picking classpath from manifest file together with you lot are checking classpath entry somewhere else. In companionship to bargain amongst java.lang.NoClassDefFoundError, ii things which are most of import is noesis of Classpath together with ClassLoader inwards Java. So, you lot should invest roughly fourth dimension on it. To start amongst you lot tin read Java Puzzlers yesteryear Joshua Bloch.


Reference:
https://docs.oracle.com/javase/8/docs/api/java/lang/NoClassDefFoundError.html

Subscribe to receive free email updates:

0 Response to "Top v Reasons of Exception inwards thread primary java.lang.NoClassDefFoundError inwards Java"

Posting Komentar