9

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

2 Answers 2

9

There seems to be issue with dependency versions,when we use commons-text and commons-lang3 together.For me it worked well after using 1.11.0 for commons-text and 3.13.0 for commons-lang3

"org.apache.commons:commons-text:1.11.0" "org.apache.commons:commons-lang3:3.13.0"

Sign up to request clarification or add additional context in comments.

2 Comments

I had the same issue with commons-lang3-3.12.0 and commons-text-1.11.0. I upgraded commons-lang3 to 3.17.0 and the issue was resolved
Same as Phil, upgrading commons-lang3 help. I wonder whether Apache have compatibility table for various libraries, given that the libraries use each other. Upvoted this answer
4

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.