NoClassDefFoundError in Tomcat for Abstract Class

I have an abstract class, Problem. It’s package is com.namespace.problem. My tomcat app calls Problem.staticMethod() on each page. I get a 500 error, NoClassDefFoundError on every page. In the debugger, I can access static fields from Problem. I can successfully place breakpoints on its instance methods. It fails to place breakpoints on static methods and any static method I call causes a NoClassDefFoundError.

Tomcat is running inside a Docker container. When I run the docker container on my local machine, there are no problems. When I run it on my AWS instance, every page has a NoClassDefFoundError.

  • Selenium in Docker container, Can we take screen shot
  • How to move Images and Containers to new Server with historical data
  • create_network(): failed to allocate gateway (x.x.x.x): Address already in use in test case
  • How to use Let's Encrypt with Docker container based on the Node.js image
  • running auditd in docker container
  • docker run with volume changes directory permission to root
  • I read that I should look for a ClassNotFoundException or a ExceptionInInitializerError but found nothing.

    I cannot initialize Problem (as it is abstract). I cannot see Problem.class in the debugger, it causes the error as well. I can’t instantiate any classes that extend Problem, I get the same error.

    What could be causing this? The point of docker is to be platform independent so I don’t know why this would happen on AWS but not my computer, I’m deploying the same WAR.

    Stacktrace:
        org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:574)
        org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:461)
        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
        org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176)
        org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)
        org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)
        org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:394)
        org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(NormalRewrittenUrl.java:213)
        org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:171)
        org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)
        org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)
        org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:394)
    root cause
    
    javax.servlet.ServletException: java.lang.NoClassDefFoundError: Could not initialize class com.namespace.problem.Problem
        org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:909)
        org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:838)
        org.apache.jsp.view.system.index_jsp._jspService(index_jsp.java:381)
        org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
        org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
        org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176)
        org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)
        org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)
        org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:394)
        org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(NormalRewrittenUrl.java:213)
        org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:171)
        org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)
        org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)
        org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:394)
    root cause
    
    java.lang.NoClassDefFoundError: Could not initialize class com.namespace.problem.Problem
        com.namespace.system.Application.setInitialState(Application.java:327)
        com.namespace.system.Application.setInitialState(Application.java:296)
        com.namespace.system.Application.setInitialState(Application.java:292)
        com.namespace.mvc.controller.Controller.<init>(Controller.java:80)
        com.namespace.mvc.controller.SystemController.<init>(SystemController.java:20)
        org.apache.jsp.view.system.index_jsp._jspService(index_jsp.java:122)
        org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
        org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
        org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176)
        org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)
        org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)
        org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:394)
        org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(NormalRewrittenUrl.java:213)
        org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:171)
        org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)
        org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)
        org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:394)
    

  • docker behind proxy doesn't use system proxy info
  • What's the main advantage of using replicas in Docker Swarm Mode?
  • Using dockerfile ADD and COPY commands on Mac OS X
  • Docker service start failed
  • How do I use the git commit id as a docker image tag in maven?
  • how does incorrect Docker postGIS command RUN succesfully?
  • One Solution collect form web for “NoClassDefFoundError in Tomcat for Abstract Class”

    Apparently, there was an XML config file, whose path was defined by an env var. The var on my local machine was correct, on AWS it was wrong because someone else in my repo renamed the file. Apparently, for some reason, instead of a sensible error about the file not existing, you get a NoClassDefFoundError from a class that doesn’t even use the config file.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.