0

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?

user906153
  • 1,218
  • 8
  • 30
  • 43

4 Answers4

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

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I put the jar with the src (which has the HubPortal class in it) and it fixed the error I was encountering, however, it did produce another one. (I would put it here, but I went over the character limit!) http://pastebin.com/s5Ldg7hz – user906153 Nov 16 '11 at 21:44
  • Apparently there are other dependencies, but the exception doesn't contain helpful information now. Putting Java code in normal Java classes instead of JSP files should result in more clear exceptions. See also http://stackoverflow.com/questions/3177733/how-to-avoid-java-code-in-jsp-files/3180202#3180202 – BalusC Nov 16 '11 at 21:48
  • Okay, thanks. But, any idea as to why this error appeared out of the blue? – user906153 Nov 16 '11 at 21:51
  • Either the classpath has been messed up (or, contrarily, has been cleaned up and thus exposed hidden problems), or some circumstance changed which caused HubPortal to indirectly instantiate Log4j while it did not do that by default, etc. – BalusC Nov 16 '11 at 21:54
3

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!
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
bilash.saha
  • 7,226
  • 2
  • 35
  • 40
0

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

r0ast3d
  • 2,639
  • 1
  • 14
  • 18
0

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

Matthew Farwell
  • 60,889
  • 18
  • 128
  • 171