简体   繁体   中英

java.lang.NoClassDefFoundError when hit the jsp

I have code, in which I have package called:

package com.test.core.it;

All classes inside this package only. There is a .jsp file, which has this line of code:

test.executeAllTestCase();

the test is an instance of TestA which is in the package com.test.core.it . executeAllTestCase has line like:

TestB.getInstance()

TestB is also in same package.

I builded the war and deployed to tomcat. When hit the url:

http://localhost:8080

the jsp is getting called, which is throwing me the exception:

javax.servlet.ServletException: java.lang.NoClassDefFoundError: Could not initialize class com.test.core.it.TestB
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:912)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:841)

I'm not sure, where I'm making mistake.

Edit

I can see the classes are loaded in WEB-INF -> classes -> <package wise directory> -> TestA.class, TestB.class

Maybe an exception during static initialization of class TestB.
First time. when java loads a class, the static initializers are performed. If you have a exception in this, java will not try again to load the class definition, instead a NoClassDefFoundError is thrown. So maybe there is an oversight exception before the first NoClassDefFoundError

This usually happens if either at runtime the class is not found: - make sure your classpath contains the jar. or two classes with the same name exists on the classpath, in this case the JVM does not know which class to load.

  • check your classpath and make sure it is the same as your classpath during compile time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM