java - 仅在 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;
}
}
解决方案
发现问题了。。
我使用了这段代码,发现 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();
}
推荐阅读
- python - 来自带有 python-requests 的 Django 模板中的 r.text 的不完整 HTML
- java - (Java Swing) 如何在 GUI 中将图像添加到按钮?
- linux - 为什么 echo 命令解释基目录的变量?
- excel - Excel - 如果 B 列的值在 D 列中,则 A 列的总和值。我该怎么做?
- javascript - 处理具有可变结构的对象数组
- flutter - 如何确定图像是资产还是网络图像
- java - 如何设置图像视图的圆角
- flutter - 颤动关闭警报对话框而不弹出屏幕
- python - 当输入条件为真时,'If'循环'和不打印消息
- css - 多行响应::边框前