我有一个java maven项目,我使用jax-rs进行http GET,POST请求。在其他控制器类中,我在另一个类中调用getHTML内容(使用jsoup)。然后这个NoClassDefFroundErrorr
来了。我已经添加了maven依赖项并添加了jar。出现此错误的原因是什么?
这是我的jsoup代码:
public static ArrayList<StringBuilder> getHTMLContent(ArrayList newsUrl) throws IOException, InterruptedException {
ArrayList<StringBuilder> descriptionList = new ArrayList();
Document document;
for (int i = 0; i < 15; i++) {
System.out.println(newsUrl.get(i));
try {
Connection.Response response = Jsoup.connect((String) newsUrl.get(i))
.ignoreContentType(true)
.userAgent("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0")
.referrer("http://www.google.com")
.timeout(12000)
.followRedirects(true)
.execute();
document = response.parse();
Elements paragraphs = document.body().select("p");
StringBuilder content = new StringBuilder();
for (Element element : paragraphs) {
//removing advertisement tag
if (!element.text().equals("Advertisement") &&
!element.text().contains("|") &&
!element.text().contains(":") &&
!(element.text().trim().split(" ").length == 1) &&
!(element.text().trim().contains("Home Page"))) {
content.append(element.text());
content.append("\n");
}
}
descriptionList.add(content);
}catch (Exception e){
}
}
return descriptionList;
}
我在其余控制器中调用这样的方法
ArrayList<StringBuilder> descriptions = api_client.getHTMLContent(urls);