Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
694 views
in Technique[技术] by (71.8m points)

maven 3 - Jena TDB java.lang.ExceptionInInitializerError

I'm using Jena TDB for loading an RDF dataset and making SPARQL queries against it. I'm using the following maven dependency:

<dependency>
    <groupId>org.apache.jena</groupId>
    <artifactId>apache-jena-libs</artifactId>
    <type>pom</type>
    <version>3.0.1</version>
</dependency>

And here's the java code where I'm trying to create a TDB dataset:

public void loadDirectory(String outputFile){      
    Dataset dataset = TDBFactory.createDataset(directoryPath);      
    Model tdb = dataset.getDefaultModel();      
    FileManager.get().readModel(tdb, outputFile);      
    tdb.close();      
    dataset.close();      
    LOG.info("RDF dataset loaded to memory");      
}      

It's failing on the first line of the function: TDBFactory.createDataset( directoryPath ) with the following error message:

Exception in thread "main" java.lang.ExceptionInInitializerError
    at org.sdw.model.JenaModel.loadDirectory(JenaModel.java:69)
    at org.sdw.Main.main(Main.java:75)
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.tdb.TDBFactory.<clinit>(TDBFactory.java:40)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The POM uses the shade plugin. It needs to manage services files (META_INF/services/) with a ServicesResourceTransformer transformer.

Add the following transformed to your POM file:

<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />

See <transformers> here for example: https://github.com/apache/jena/blob/master/jena-fuseki2/jena-fuseki-server/pom.xml


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...