我是boilerpipe
的新手,正在尝试以下基本代码:
package contentExtraction;
import java.net.URL;
import de.l3s.boilerpipe.extractors.ArticleExtractor;
public class ContentExtractor {
public static void main(String[] args) throws Exception {
final URL url = new URL(
// "http://www.l3s.de/web/page11g.do?sp=page11g&link=ln104g&stu1g.LanguageISOCtxParam=en"
"http://www.dn.se/nyheter/vetenskap/annu-godare-choklad-med-hjalp-av-dna-teknik"
);
System.out.println(ArticleExtractor.INSTANCE.getText(url));
}
}
但是尝试运行以上代码时出现以下错误:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xerces/parsers/AbstractSAXParser
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at de.l3s.boilerpipe.sax.BoilerpipeSAXInput.getTextDocument(BoilerpipeSAXInput.java:51)
at de.l3s.boilerpipe.extractors.ExtractorBase.getText(ExtractorBase.java:69)
at de.l3s.boilerpipe.extractors.ExtractorBase.getText(ExtractorBase.java:87)
at contentExtraction.ContentExtractor.main(ContentExtractor.java:16)
Caused by: java.lang.ClassNotFoundException: org.apache.xerces.parsers.AbstractSAXParser
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 16 more
我搜索了该错误,并遇到了this link。我以为我的依赖项中缺少
xercesImpl.jar
。我包含了相同的内容,但我的代码仍给出了相同的错误。有什么问题 最佳答案
我自己想出了解决方案。 boilerpipe
jar还具有其他依赖性。我将项目转换为maven项目,包括依赖项:
<dependency>
<groupId>com.syncthemall</groupId>
<artifactId>boilerpipe</artifactId>
<version>1.2.1</version>
</dependency>
当我构建以上项目时,我可以看到实际上在Maven Dependencies文件夹中导入了4个jar:
boilerpipe-1.2.1.jar
nekohtml-1.9.18.jar
xercesImpl-2.11.0.jar
xml-apis-1.4.01.jar