Search code examples
javaurlencodeapache-commons

java.lang.NoClassDefFoundError: org/apache/commons/lang3/Range


I am trying to encode html view source as \u03C4. Got help from this ANSWER but first I used org.apache.commons.lang3 but seen THIS LINK that its moved to org.apache.commons.text

Here is my code:

import org.apache.commons.text.StringEscapeUtils;
import org.apache.commons.text.translate.UnicodeUnescaper;

public class HTMLEncoder extends Common {

    public static String encode(String source) {
        String escaped = StringEscapeUtils.escapeJava(source);
        String utfChars = new UnicodeUnescaper().translate(escaped);
    return utfChars; 
    }
}

This code throws the following error:

java.lang.NoClassDefFoundError: org/apache/commons/lang3/Range
org.apache.commons.text.translate.NumericEntityEscaper.<init>(NumericEntityEscaper.java:46)
org.apache.commons.text.translate.NumericEntityEscaper.between(NumericEntityEscaper.java:85)
org.apache.commons.text.StringEscapeUtils.<clinit>(StringEscapeUtils.java:162)
parvaz.aero.commons.method.HTMLEncoder.encode(HTMLEncoder.java:8)
parvaz.aero.user.categories.controller.SelectAll.doGet(SelectAll.java:60)
javax.servlet.http.HttpServlet.service(HttpServlet.java:626)
javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

Question-1: Its using apache common text package but throwing error about apache commons lang3?
Question-2: How to fix it?

Any advice please

Best Regards


Solution

  • From the source code it looks like there is a dependency on the Apache Commons Lang 3 library. You can download it from here.

    I was able to resolve the error by importing the commons-lang3-3.12.0.jar file into my project, the same way I imported the commons-text-1.9.jar file (your file versions may be different).