0

I am writing a character filter function, using commons-text-1.6.jar.
The log function is okay, but then this error shows up:

java.lang.NoClassDefFoundError: Could not initialize class org.apache.commons.text.StringEscapeUtils
    cc.openhome.web.EscapeWrapper.getParameter(EscapeWrapper.java:15)
    cc.openhome.controller.Login.doPost(Login.java:30)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    cc.openhome.web.EscapeFilter.doFilter(EscapeFilter.java:16)

Code:

package cc.openhome.web;

import org.apache.commons.text.StringEscapeUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrappe

public class EscapeWrapper extends HttpServletRequestWrapper {
    public EscapeWrapper(HttpServletRequest req){enter code here
        super(req);
    }

    public String getParameter(String name){
        String value = getRequest().getParameter(name);
        return StringEscapeUtils.escapeHtml4(value);
    }
}
Federico Grandi
  • 6,578
  • 4
  • 29
  • 49
Changli Zhu
  • 1
  • 1
  • 2

1 Answers1

1

Apperantly a lot of things can cause this, but I found a thread that discusses this in greter detail, you should check this out!

EDIT: The top answers from that thread:

  1. (Accepted): This is caused when there is a class file that your code depends on and it is present at compile time but not found at runtime. Look for differences in your build time and runtime classpaths.

  2. While it's possible that this is due to a classpath mismatch between compile-time and run-time, it's not necessarily true.

  3. java.lang.ClassNotFoundException This exception indicates that the class was not found on the classpath. This indicates that we were trying to load the class definition, and the class did not exist on the classpath.

  4. java.lang.NoClassDefFoundError This exception indicates that the JVM looked in its internal class definition data structure for the definition of a class and did not find it. This is different than saying that it could not be loaded from the classpath. Usually this indicates that we previously attempted to load a class from the classpath, but it failed for some reason - now we're trying to use the class again (and thus need to load it, since it failed last time), but we're not even going to try to load it, because we failed loading it earlier (and reasonably suspect that we would fail again). The earlier failure could be a ClassNotFoundException or an ExceptionInInitializerError (indicating a failure in the static initialization block) or any number of other problems. The point is, a NoClassDefFoundError is not necessarily a classpath problem.

Gtomika
  • 835
  • 6
  • 20
  • 1
    Sorry, I thought these protected questions are kind of like achieved as well. I copied some answers here – Gtomika Nov 24 '18 at 14:59