I've written some code that manipulates RDF, and so is dependent on the jena framework. I'm trying to compile / package it using maven. The compilation completes, but when I try and run the generated jar file, I get:
Exception in thread "main" java.lang.ExceptionInInitializerError
at my.package.name.ClassName.<clinit>(SchemaAPI.java:96)
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.
This has been discussed before (e.g. here and here) but I have modified my pom file to include the shade plugin - and this hasn't solved the issue, and I've hit a bit of a brickwall...
Based on the comments in the discussions in the links above I have checked my META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle
file in my my-project-0.1-jar-with-dependencies.jar
file and it does indeed contain the reference to TDB (org.apache.jena.tdb.sys.InitTDB
) - so I know that this is (almost certainly) the cause of the issue but I'm no nearer to finding a solution...
I'm also including the maven-dependency-plugin
and the maven-compiler-plugin
- I assume these won't be causing any conflict?
Further info
Some extra info in response to Andy S's comment. The relevant part of my pom file is:
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>uk.co.domain.mypackage.MyClass</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer" />
<transformer implementation="org.apache.maven.plugins.shade.resource.ApacheNoticeResourceTransformer">
<addHeader>false</addHeader>
</transformer>
</transformers>
The relevant file in META-INF
only contains one class:
$more META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle
org.apache.jena.tdb.sys.InitTDB
$
I've also tried adding
JenaSystem.init();
at the beginning of my main class, but this hasn't helped