2

I am trying to run the first example that comes with the official Jena documentation.

Here is the error I am getting when I run the command "java -jar target/my-app-1.0-SNAPSHOT-jar-with-dependencies.jar":

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.ExceptionInInitializerError
    at com.mycompany.app.RdfWriter.main(RdfWriter.java:13)
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:248)
    at org.apache.jena.tdb.sys.InitTDB.start(InitTDB.java:29)
    at org.apache.jena.system.JenaSystem.lambda$init$2(JenaSystem.java:119)
    at java.util.ArrayList.forEach(ArrayList.java:1249)
    at org.apache.jena.system.JenaSystem.forEach(JenaSystem.java:194)
    at org.apache.jena.system.JenaSystem.forEach(JenaSystem.java:171)
    at org.apache.jena.system.JenaSystem.init(JenaSystem.java:117)
    at org.apache.jena.rdf.model.ModelFactory.<clinit>(ModelFactory.java:49)
    ... 1 more

Here is my pom file:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>my-app</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.jena</groupId>
        <artifactId>apache-jena-libs</artifactId>
        <version>3.1.1</version>
        <type>pom</type>
    </dependency>
    <dependency> 
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.7</version>
    </dependency> 
  </dependencies>


    <build>
      <plugins>
        <plugin>
          <artifactId>maven-assembly-plugin</artifactId>
          <configuration>
            <archive>
              <manifest>
                <mainClass>com.mycompany.app.RdfWriter</mainClass>
              </manifest>
            </archive>
            <descriptorRefs>
              <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
          </configuration>
        </plugin>
      </plugins>
    </build>

</project>

And here is the only file that I have so far:

package com.mycompany.app;

import org.apache.jena.rdf.model.*;
import org.apache.jena.vocabulary.*;

public class RdfWriter {

    static String personURI    = "http://somewhere/JohnSmith";
    static String fullName     = "John Smith";

    public static void main(String[] args) {
        // create an empty model
        Model model = ModelFactory.createDefaultModel();
       // create the resource
       Resource johnSmith = model.createResource(personURI);
      // add the property
      johnSmith.addProperty(VCARD.FN, fullName);
        System.out.println("this is rdf writer");
    }

}

I only want to get started, so if there is way to fix the pom or even not using maven if it is simpler, please let me know.

I added a new dependency to the dependencies in my pom file after Tahir mentioned that in the answer like this:

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-simple</artifactId>
    <version>1.6.2</version>
</dependency>

And now I am getting this error:

Exception in thread "main" java.lang.ExceptionInInitializerError
    at com.mycompany.app.RdfWriter.main(RdfWriter.java:14)
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:248)
    at org.apache.jena.tdb.sys.InitTDB.start(InitTDB.java:29)
    at org.apache.jena.system.JenaSystem.lambda$init$2(JenaSystem.java:119)
    at java.util.ArrayList.forEach(ArrayList.java:1249)
    at org.apache.jena.system.JenaSystem.forEach(JenaSystem.java:194)
    at org.apache.jena.system.JenaSystem.forEach(JenaSystem.java:171)
    at org.apache.jena.system.JenaSystem.init(JenaSystem.java:117)
    at org.apache.jena.rdf.model.ModelFactory.<clinit>(ModelFactory.java:49)
    ... 1 more

Thanks

Karim Mtl
  • 1,223
  • 3
  • 11
  • 39
  • Asked and answered on the Jena users list: https://lists.apache.org/thread.html/266bec0d082f1b4b79d3b413bdfd9a944ac0bfb1b0b02a1bda992669@%3Cusers.jena.apache.org%3E – AndyS Feb 10 '17 at 23:44
  • @AndyS, I added a link for the eclipse option, the answer you are metioning says this: I don't know how to combine them with the assembly plugin. Hopefully somebody knows here. – Karim Mtl Feb 11 '17 at 19:06

3 Answers3

2

When you repacked the jar with the assembly plugin, the ServiceLoader files got mangled. ServiceLoader is a standard Java feature Jena uses to provide initialization across jars.

You need to combine all the files called

META-INF/services/org.apache.jena.system.JenaSubsystemLifecycle

from the jars (there are several of these files, different contents).

If you really must build a combined jar, rather than say use "mvn exec:exec", then use the shade plugin with <transformer implementation= "org.apache.maven.plugins.shade.resource.ServicesResourceTransformer/>.

AndyS
  • 16,345
  • 17
  • 21
1

You need to add following jar file in your classpath:
slf4j-simple-1.6.1.jar

Just add this dependency and see whether it will solve your problrm or not?

<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.1</version>

Tahir Hussain Mir
  • 2,506
  • 2
  • 19
  • 26
0

The instructions found here: http://www.iandickinson.me.uk/articles/jena-eclipse-helloworld/ worked for me.

I still think it should not be complicated to make a valid pom for this. If nobody provides a pom that allows this to run without errors, I will accept my own answer.

Thanks

Karim Mtl
  • 1,223
  • 3
  • 11
  • 39