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)
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