gpt4 book ai didi

Java HtmlUnit java.lang.NoClassDefFoundError : org/w3c/css/sac/ErrorHandler stack overflow

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:59:34 31 4
gpt4 key购买 nike

尝试在 HtmlUnit 上做教程示例,以便我可以通过 Java 连接到网页。当我尝试运行它时出现以下错误:

java.lang.NoClassDefFoundError: org/w3c/css/sac/ErrorHandler stack overflow

这是我的代码:

package Http;


import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import org.junit.Assert;
import org.junit.Test;

public class Facebook {
@Test
public void homePage() throws Exception {
try (final WebClient webClient = new WebClient()) {
final HtmlPage page = webClient.getPage("http://htmlunit.sourceforge.net");
Assert.assertEquals("HtmlUnit - Welcome to HtmlUnit", page.getTitleText());

final String pageAsXml = page.asXml();
Assert.assertTrue(pageAsXml.contains("<body class=\"composite\">"));

final String pageAsText = page.asText();
Assert.assertTrue(pageAsText.contains("Support for the HTTP and HTTPS protocols"));
}
}
}

我有 httpcore 4.4.1 httpclient 4.4.1 htmlunit.2.17 全部导入

最佳答案

您很可能缺少依赖项 org.w3c.css:sac , 请参阅 SAC project page了解更多信息。将它包含在您的 POM 中或将 jar 放在类路径中。

关于Java HtmlUnit java.lang.NoClassDefFoundError : org/w3c/css/sac/ErrorHandler stack overflow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30304812/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com