0

i have this java web application running on 4 servers. The newest server ( just setting up ) is failing with the error "java.lang.NoSuchMethodError: org.htmlparser.lexer.Lexer.parseCDATA()Lorg/htmlparser/Node" when running the code below.

I have 1 server is running locally on my mac. 2 servers are running Centos 6.10 / java 1.8.0_242 / tomcat-8.5.54 The newest server (the one that is failing ) is running Centos 6.10 / java 1.8.0_242 / tomcat-8.5.54

i have copied all the jars from the working Centos server to the broke one

I am at a loss. Would love to hear some ideas on how to debug/resolve this....

The Code running is pretty simple Another part that also confuses me, is if the jar was not found wouldnt Parser.createParser blow up and i have added debug code to make sure parser_c is not null

import org.htmlparser.Node;
import org.htmlparser.Parser;
import org.htmlparser.tags.ImageTag;
import org.htmlparser.tags.LinkTag;
import org.htmlparser.util.ParserException;

public class SignatureTools {
    public static String getURLFromSignature(String signature) throws ParserException {
        System.out.println("[getURLFromSignature]");
        if ( signature == null ){ return null;}
        Parser parser_c = Parser.createParser(signature, null);
        Node nodes_c[] = parser_c.extractAllNodesThatAre(LinkTag.class);
        String mkURL = null;
        for (Node node : nodes_c) {
            if (node != null && node instanceof LinkTag && ((LinkTag) node).getAttribute("href") != null) {
                String href = ((LinkTag) node).getAttribute("href");
                if ( href.contains("https://www.thedomain.com") ){
                    mkURL = href;
                }
            }
        }
        return URL;
    }
}
randy
  • 1,685
  • 3
  • 34
  • 74
  • is htmlparser jar is available on classpath. Please verify. – Joy Apr 26 '20 at 06:45
  • Joy thanks for responding. Looking at the tomcat docs "Class loaders are created for each deployed Context, which load all classes and JAR files contained in each web application's WEB-INF/classes and WEB-INF/lib, respectively and in that order. These resources are only visible to the web application that loads them." and htmlparser.jar is in my lib directory – randy Apr 26 '20 at 13:48
  • Not familiar with `org.htmlparser`, but looking on Maven Central, it looks like it's utilizes 2 jars: `htmlparser` and `htmllexer`. Make sure there's not a version mismatch between the two jars. – TrogDor Apr 26 '20 at 14:29

1 Answers1

0

found the problem..

i used this bit of code and found that Lexer was being loaded from a different jar instead of htmllexer.jar

Lexer lexer = new Lexer();
        try {
            System.out.println( "Lexer---->" + new File(Lexer.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getPath());
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
randy
  • 1,685
  • 3
  • 34
  • 74