user906153
user906153

Reputation: 1218

Getting an odd java.lang.NoClassDefFoundError exception

I'm getting an odd exception when running my java web project. It seems like this 'randomly' happened after I saved some changes to one of my JSPs. I don't ever remember changing around any settings. I've never run into any errors like this before from this project, it's had no problem finding the HubPortal class before.

Here's the full stack trace:

org.apache.jasper.JasperException: An exception occurred processing JSP page /hubmainpage.jsp at line 7

4: %>
5: <%
6: String responsepage = request.getParameter("show");
7: HubPortal hp = new HubPortal();
8: List processList = hp.getProcessList();
9: List clientList = hp.getClientList();
10: List transList = hp.getTransactionTypeList();


Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:521)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:412)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause 

javax.servlet.ServletException: java.lang.NoClassDefFoundError: org/apache/log4j/Logger
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:865)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:794)
    org.apache.jsp.hubmainpage_jsp._jspService(hubmainpage_jsp.java:783)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause 

java.lang.NoClassDefFoundError: org/apache/log4j/Logger
    com.middleware.hts.HubPortal.<clinit>(HubPortal.java:23)
    org.apache.jsp.hubmainpage_jsp._jspService(hubmainpage_jsp.java:66)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

Any ideas as to why I'm all of a sudden encountering this error?

Upvotes: 0

Views: 19521

Answers (4)

BalusC
BalusC

Reputation: 1108722

7: HubPortal hp = new HubPortal();

root cause 

java.lang.NoClassDefFoundError: org/apache/log4j/Logger
    com.middleware.hts.HubPortal.<clinit>(HubPortal.java:23)

This means that the log4j jar file is missing in webapp's runtime classpath while it is been required by the HubPortal class. You need to put it in the same place as the JAR file containing the HubPortal class, for example the /WEB-INF/lib folder or wherever else the HubPortal class is.

Upvotes: 5

bilash.saha
bilash.saha

Reputation: 7306

In addition to everyones answer I want to say some tips For java.lang.NoClassDefFoundError or java.lang.ClassNotFoundException:

  1. You should first confirm your classpath
  2. You need to ensure the required classes under %CONTEXT-ROOT%/WEB-INF/Classes(Servlet directory) or If the dependent classes availble to you as JAR then it is inside %CONTEXT-ROOT%/WEB-INF/lib/xyz.jar. Remember the container needs to access these classes during runtime!

Upvotes: 3

r0ast3d
r0ast3d

Reputation: 2635

Looks like your HubPortal class is not able to find the Logger class, make that available as part of your web-inf.

Upvotes: 0

Matthew Farwell
Matthew Farwell

Reputation: 61705

This is because you're not deploying the log4j jar. This should be part of your war, in WEB-INF/lib.

Upvotes: 0

Related Questions