ClassNotFoundException or NoClassDefFoundError while using JBoss
Applies to:
JBoss
Description:
There is little difference between the two:
a. NoClassDefFoundError represents an unfound import
b. ClassNotFoundException represents dynamic classloading
Cause:
a.You forgot to add the class
b. You forgot to add a class that this class depends upon
c. You compiled the class for the wrong version
d. The class is not visible from where it is being loaded
e. You are deploying on Windows (NTFS)
f. Some other error
g. Not using the correct api
JAVA-JBoss "jboss 6" noclassdeffounderror "wrong name", "no class found" vs "noclassdeffound", (wrong name: jboss, class not found exception of war deploying ear glassfish v3.1, class not found exception vs no class def found exception, class not loaded in jboss 5 noclassdeffound error, classnotfound for ear with war, classnotfoundexception and noclassdeffounderror, classnotfoundexception during war deployment jboss 6, classnotfoundexception ear war, classnotfoundexception in deploy in war in jboss, classnotfoundexception in jboss 5 war, classnotfoundexception jboss war, classnotfoundexception vs noclassdeffounderror, classnotfoundexception wrong name, classnotfoundexception: org.hibernate.hql.ast.hqltoken glassfish ear, deploy "class not found" "jboss 6", diagnostics jboss classnotfoundexception, difference between classnotfoundexception and noclassdeffounderror, dy, ear deployment classnotfoundexception jboss 6, ear jboss noclassdeffounderror, ear two war class not found jboss, error, how to use static block actionform, hqltoken glassfish, j, javacompiler noclassdeffounderror "wrong name", jboss "noclassdeffounderror" ear, jboss 5 cache classnotfoundexception, jboss 5 ear deployment classnotfoundexception, jboss 5 hibernate noclassdefinationfound, jboss 5 load class outside the war, jboss 6 class not found, jboss 6 class not found exception, jboss 6 classnotfoundexception, jboss 6 ear classnotfoundexception, jboss 6 ear exploded format classnotfound error, jboss 6 ear noclassdeffounderror, jboss 6 war classnotfoundexception, jboss 6.0 ear class not found, jboss class not found exception, class is there, jboss classdefnotfound, jboss classnotfoundexception, jboss classnotfoundexception controller, jboss classnotfoundexception jar in war, jboss ear deployment classnotfound, jboss exceptions with solutions, jboss noclassdeffound, jboss noclassdeffound module.common, jboss noclassdeffounderror, jboss noclassdeffounderror inside war, jboss noclassdeffounderror war, jboss noclassdeffounderror web-inf/classes/, jboss noclassdeffounderror while class is in ear, jboss noclassdeffounderror wrong name, jboss noclassdeffoundexception, jboss static initialization block no class def found, jboss war class not found, jboss war classnotfound, jboss war classnotfoundexception, jboss war ear classdefnotfound, jboss war noclassdeffounderror, jboss5 war classnotfound servlet, jboss6 classnotfound exception, jboss6 classnotfounderror, jboss6 classnotfoundexception, junit noclassdeffounderror war packed in ear, lrm-00118: syntax error at '=' at the end of input, multiple ear jboss 6 noclassdeffound, no class defination found when creating war using jboss tools, no class found deploy war, noclassdeffound error while loading a class using classloader in jboss application server, noclassdeffound jboss, noclassdeffound war inside ear "jboss" 5, noclassdeffounderror, noclassdeffounderror "wrong name" controller, noclassdeffounderror class.forname solution, noclassdeffounderror classnotfoundexception, noclassdeffounderror jboss ear, noclassdeffounderror represents an unfound import, noclassdeffounderror static block, noclassdeffounderror war, noclassdeffounderror web-inf/classes jboss, noclassdeffounderror while jar in ear jboss, noclassdeffounderror while testing war from weblogic, noclassdeffounderror while using javamail api, noclassdeffounderror: (wrong name: jboss, noclassdeffoundexception jboss, nocloassdeffounderror, jboss rmi call, isloated classloader, war classnotfoundexception, war classnotfoundexception jboss startup, war in ear noclassdeffounderror, war noclassdeffounderror, war noclassdeffounderror class.forname
a. Use jar -tf whatever.jar to show the class is in the correct place
b. Use javap to look at the class (assuming you don’t have the source code)
c. The class is compiled for java5 but you are trying to use it on java1.4. Note that this can happen when the subclass was compiled with the correct version but its superclass was not. Often, java will report the NoClassDefFoundError on the subclass when the problem was really the fact that its superclass was compiled with the wrong version.
d. This happens when you have an isolated deployment (like a war) and you try to load it from outside the war. This may not be directly. e.g. A war class loads a class from outside the war which in turn tries to load a class from inside the war.
e. Path names in NTFS have a hard limit of 255 characters, which means that if the exploded full path is longer than 255, the path is truncated. For example this one which contains 269 characters:
/C:/JBoss/jboss-4.0.4.GA/server/Server1/tmp/deploy/tmp8590CCFF_Administration-test-blabla.ear-contents/CCFF_Administration_blabla-exp.war/WEB-INF/classes/me/you/house1/ccff/administration/controller/web/actionForms/logconfiguration/LogConfigurationListActionForm.class
This path would through an exception like this because it would truncated to something like this:
/C:/JBoss/jboss-4.0.4.GA/server/Server1/tmp/deploy/tmp8590CCFF_Administration-test-blabla.ear-contents/CCFF_Administration_blabla-exp.war/WEB-INF/classes/me/you/house1/ccff/administration/controller/web/actionForms/logconfiguration/LogConfigurationListAc
f. The class has a static initialization block that is throwing an error
“);
public class MyClass{
static{
throw new Error(“Usually not reported in the NoClassDefError if this is loaded by an import
}
}
g. If you use Class.forName() this is MyClass.class.getClassLoader().loadClass(…) which will start from the classloader where your class is deployed.
You should use Thread.currentThread().getContextClassLoader().loadClass(…) to load from the current application’s classloader.