首页 > 解决方案 > 仅在 1 或 4 个服务器上获得 java/tomcat 异常

问题描述

我在 4 个服务器上运行这个 java web 应用程序。运行下面的代码时,最新的服务器(刚刚设置)失败并出现错误“java.lang.NoSuchMethodError: org.htmlparser.lexer.Lexer.parseCDATA()Lorg/htmlparser/Node”。

我有 1 台服务器在我的 Mac 上本地运行。2 台服务器正在运行 Centos 6.10 / java 1.8.0_242 / tomcat-8.5.54 最新的服务器(失败的服务器)正在运行 Centos 6.10 / java 1.8.0_242 / tomcat-8.5.54

我已将所有 jar 从正常工作的 Centos 服务器复制到损坏的

我很茫然。很想听听一些关于如何调试/解决这个问题的想法......

运行的代码非常简单 另一个让我感到困惑的部分是,如果找不到 jar,Parser.createParser 不会爆炸,我添加了调试代码以确保 parser_c 不为空

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;
    }
}

标签: javatomcat8

解决方案


发现问题了。。

我使用了这段代码,发现 Lexer 是从另一个 jar 而不是 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();
        }

推荐阅读