当我们在Eclipse的JUNIT(4.11)环境中运行以下代码时,jena-osgi 3.0.1 ModelFactory.createDefaultModel()引发ExceptionInInitializerError:

 // Convert the XML to RDF model
 StringReader stringReader = new StringReader(xml);
 Model model = ModelFactory.createDefaultModel();
 model.read(stringReader, null, RDFLanguages.RDFXML.getLabel());


堆栈跟踪如下:

java.lang.ExceptionInInitializerError
...
Caused by: java.lang.NullPointerException
    at org.apache.jena.tdb.sys.EnvTDB.processGlobalSystemProperties(EnvTDB.java:33)
    at org.apache.jena.tdb.TDB.init(TDB.java:250)
    at org.apache.jena.tdb.sys.InitTDB.start(InitTDB.java:29)
    at org.apache.jena.system.JenaSystem.lambda$init$40(JenaSystem.java:114)
    at java.util.ArrayList.forEach(ArrayList.java:1249)
    at org.apache.jena.system.JenaSystem.forEach(JenaSystem.java:179)
    at org.apache.jena.system.JenaSystem.forEach(JenaSystem.java:156)
    at org.apache.jena.system.JenaSystem.init(JenaSystem.java:111)
    at org.apache.jena.rdf.model.ModelFactory.<clinit>(ModelFactory.java:49)
    ... 25 more


如果我们使用jena-tdb 3.0.1而不是jena-osgi 3.0.1,则相同的代码也可以工作。我们需要在OSGi环境(Servicemix)中运行代码,因此使OSGi部分正常工作至关重要。

我在堆栈溢出中看到了类似的错误报告,但是没有一个解决了我们的问题。我在想也许我们缺少图书馆?这些是我们要通过Maven导入的jar:


org.apache.jena:jena-osgi:3.0.1
org.apache.servicemix.bundles:org.apache.servicemix.bundles.xerces:2.11.0_1
com.github.andrewoma.dexx:dexx-collections:0.2
commons-cli:commons-cli:1.3
commons-codec:commons-codec:1.6
commons-io:commons-io:2.4
org.apache.httpcomponents:httpclient-cache:4.2.5
xml-apis:xml-apis:1.4.01


注意:我们尝试使用Jena 3.1.0 OSGi,并且确实可以使用,但是当junit在maven中运行时,JSON-LD变得奇怪了(去除了xml名称空间前缀),但是在Eclipse中可以正常工作。

最佳答案

@RobV的答案提供了一种正确包装OSGi捆绑软件以包含所有ServiceLoader文件的解决方案。

对于在不同OSGi框架中查找ServiceLoader文件的jena-osgi问题,已升级到Jena 3.1.0(专门针对JENA-1164)。

关于java - Jena-osgi 3.0.1 ExceptionInInitializerError进程GlobalSystemProperties,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38774051/

10-13 01:15