我是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
我用Google搜索了错误并遇到了this link。我以为我在我的依赖项中缺少xercesImpl.jar
。我包括相同,仍然我的代码给出了同样的错误。有什么问题?
答案 0 :(得分:8)
我自己想出了解决方案。 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