I need to implement a simple java application to execute some queries on Seasame. I wanted to try something simple for the beginning but I am not able to initialise the repository. I was following the official guide and my program looks like this:
public class HelloSesame {
public static void main(String[] args) {
File dataDir = new File("../../resources/test.ttl");
Repository rep = new SailRepository(new NativeStore(dataDir));
rep.initialize();
RepositoryConnection conn = rep.getConnection();
//...omitted code
}
}
and my pom.xml
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.openrdf.sesame</groupId>
<artifactId>sesame-runtime</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.3</version> </dependency>
<dependency>
<groupId>org.openrdf.sesame</groupId>
<artifactId>sesame-model</artifactId>
<version>4.1.0</version>
</dependency> <dependency>
<groupId>org.openrdf.sesame</groupId>
<artifactId>sesame-repository-sail</artifactId>
<version>4.1.0</version> </dependency> <dependency>
<groupId>org.openrdf.sesame</groupId>
<artifactId>sesame-queryparser-sparql</artifactId>
<version>4.1.0</version> </dependency> <dependency>
<groupId>org.openrdf.sesame</groupId>
<artifactId>sesame-rio-api</artifactId>
<version>4.1.0</version> </dependency> <dependency>
<groupId>org.openrdf.sesame</groupId>
<artifactId>sesame-query</artifactId>
<version>4.1.0</version>
</dependency>
</dependencies>
</project>`
Every time I try to run this application I get the error:
16:02:06.436 [main] DEBUG o.openrdf.sail.nativerdf.NativeStore - Initializing NativeStore... 16:02:06.461 [main] DEBUG o.openrdf.sail.nativerdf.NativeStore - Data dir is ../../resources/test.ttl 16:02:06.540 [main] DEBUG o.openrdf.sail.nativerdf.NativeStore - NativeStore initialized Exception in thread "main" java.lang.NoClassDefFoundError: org/openrdf/query/impl/AbstractParserQuery at java.lang.ClassLoader.defineClass1(Native Method) ... at main.jridrer.functiontest.HelloSesame.main(HelloSesame.java:36) Caused by: java.lang.ClassNotFoundException: org.openrdf.query.impl.AbstractParserQuery at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 15 more
The error is thrown on rep.getConnection() method. I have tried to search on google but nothing... I have tried to search the class in the org.openrdf.query.impl package bat this class doesn’t exist there... I have tried to make MemoryStore in place of NativeStore but I get the same error. Does anyone have any idea what i can try next?
You're mixing two different versions of Sesame, which is likely causing the problem. For your dependency on sesame-runtime
you have 4.0.1, for the other libraries you have 4.1.0. In any case if you are importing specific sesame libraries (such as model, sail-nativerdf, etc), you really don't need the sesame-runtime dependency (which is a 'catch-all' dependency).
You might want to think about using Sesame's Bill Of Materials (BOM) - this makes it a little easier to juggle things as you only define the version of Sesame in one place. See the documentation for more details about this.