我使用Jena 库编写了以下代码以在网页上打印 URI,但它显示错误。代码是
public static void test(String url)
{
try
{
System.out.println("to go");
Model read = ModelFactory.createDefaultModel().read(url);
System.out.println("to go");
StmtIterator si=read.listStatements();
System.out.println("to go");
while(si.hasNext())
{
Statement s=si.nextStatement();
Resource r=s.getSubject();
Property p=s.getPredicate();
RDFNode o=s.getObject();
System.out.println(r.getURI());
System.out.println(p.getURI());
System.out.println(o.asResource().getURI());
}
}
catch(JenaException | NoSuchElementException c)
{ }
}
谁能帮我进一步解决这个问题???
它无法创建模型读取对象。URL 是 xml 页面的网址。
出现以下错误:
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at com.hp.hpl.jena.util.Metadata.<clinit>(Metadata.java:39)
at com.hp.hpl.jena.JenaRuntime.<clinit>(JenaRuntime.java:37)
at com.hp.hpl.jena.rdf.model.impl.RDFReaderFImpl.<clinit>(RDFReaderFImpl.java:74)
at com.hp.hpl.jena.rdf.model.impl.ModelCom.<clinit>(ModelCom.java:54)
at com.hp.hpl.jena.rdf.model.ModelFactory.createDefaultModel(ModelFactory.java:142)
at com.hp.hpl.jena.rdf.model.ModelFactory.createDefaultModel(ModelFactory.java:136)
at web.crawler.WebCrawler.test(WebCrawler.java:52)
at web.crawler.WebCrawler.main(WebCrawler.java:98)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)