Using Maven is a mess

I'm trying to build a simple SNARL API example.
I'm following the " Java Programming" and "Using Maven" sections in the docs.
First of all, the updated examples (see for example here:

differ from the docs in that they say that I have to initialize the Stardog instance first, something that is missing in the docs so I have two versions of the code: one with the instance initialization (call that E1) and one without (call that E2).
Well, now by looking at "Using Maven" it's not clear what deps I need. This is not a server program, it's not an http-client program either, it's an embedded instance accessed via SNARL.
OK, I tried all the permutations of the 5 "client type dependencies" in the docs and E1 inevitably fails with a
"No driver was found which supports the connection string: 'embed://system/' whereas E2 fails with a "java.lang.NoClassDefFoundError: org/quartz/SchedulerException".
But hey, look, under "Using Maven" there is a pointer: " You can see an example of their usage in our examples repository on Github", cool!
Not so fast, this is still a Gradle example and is way outdated.
So I switched to the develop version of the Gradle buildfile and I tried to reconstruct the same structure with Maven. The results looks like the following:

		<dependency>
			<groupId>com.complexible.stardog</groupId>
			<artifactId>server</artifactId>
			<version>${stardog.version}</version>
			<type>pom</type>
		</dependency>
		<dependency>
			<groupId>com.complexible.stardog</groupId>
			<artifactId>client-http</artifactId>
			<version>${stardog.version}</version>
			<type>pom</type>
		</dependency>
		<dependency>
			<groupId>com.stardog.stark.query</groupId>
			<artifactId>stardog-stark-query-api</artifactId>
			<version>${stardog.version}</version>
		</dependency>
		<dependency>
			<groupId>com.stardog.stark.io</groupId>
			<artifactId>stardog-stark-io-api</artifactId>
			<version>${stardog.version}</version>
		</dependency>
		<dependency>
			<groupId>com.stardog.stark.query.io</groupId>
			<artifactId>stardog-stark-query-io</artifactId>
			<version>${stardog.version}</version>
		</dependency>
		<dependency>
			<groupId>com.complexible.stardog</groupId>
			<artifactId>client-embedded</artifactId>
			<version>${stardog.version}</version>
		</dependency>
		<dependency>
			<groupId>com.complexible.stardog.prov</groupId>
			<artifactId>stardog-prov</artifactId>
			<version>${stardog.version}</version>
			<scope>runtime</scope>
		</dependency>
		<dependency>
			<groupId>com.complexible.stardog.skos</groupId>
			<artifactId>stardog-skos</artifactId>
			<version>${stardog.version}</version>
			<scope>runtime</scope>
		</dependency>
		<dependency>
			<groupId>com.complexible.stardog.rdf4j</groupId>
			<artifactId>stardog-rdf4j</artifactId>
			<version>${stardog.version}</version>
		</dependency>
		<dependency>
			<groupId>org.eclipse.rdf4j</groupId>
			<artifactId>rdf4j-runtime</artifactId>
			<version>2.2.4</version>
		</dependency>
		<dependency>
			<groupId>com.complexible.stardog.jena</groupId>
			<artifactId>stardog-jena</artifactId>
			<version>${stardog.version}</version>
		</dependency>
		<dependency>
			<groupId>com.complexible.stardog.gremlin</groupId>
			<artifactId>stardog-gremlin</artifactId>
			<version>${stardog.version}</version>
		</dependency>

ok, lots of stuff that I do not need but I can try to trim them out later... build... run... same results as above.
OK, let's assume that Stardog.builder().create() is really needed and get rid of the java.lang.NoClassDefFoundError: org/quartz/SchedulerException by explicitly adding quartz to the deps...
Good we are making progress, not it complains about Caffeine: java.lang.NoClassDefFoundError: com/github/benmanes/caffeine/cache/Caffeine.
And if I add Caffeine to the deps I get Error in custom provider, java.lang.RuntimeException: Could not load system index: system.
OK, going nowhere.
Now the questions are:

  1. is Stardog.builder().create() needed? If so please update the docs, if it is not please update the examples.
  2. can you please provide me a minimal set of Maven deps to run a simple SNARL API program with an embedded server (and maybe update/improve the Maven docs since you are at that)?

Thanks!

Hello and welcome!

The docs are indeed not explicit about this, however the Stardog.builder().create() call is needed if you intend to start up the embedded server, as it seems you want to do. I should note that this is the new and improved way to do this as of Stardog 6, which could explain the slight disconnect. The docs section does seem to go off the assumption that you are connecting to the embedded server, so perhaps it should be more explicit about this, however if you were running a local instance of the Stardog server you would NOT need this call, as you could just point the AdminConnectionConfiguration to that instance instead.

Because you want to run the embedded server, you actually do need the server dependency. You're technically correct about it not being an HTTP client but rather an embedded one, and we do actually have a client-embedded artifact, but client-http brings that (as well as everything else) in along with it.

I was able to get the exact main method from the stardog-examples repository to which you linked by bringing in just server and client-http as follows:

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.stardog</groupId>
    <artifactId>java-sandbox-maven</artifactId>
    <version>1.0-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <properties>
        <stardog.version>6.1.3</stardog.version>
    </properties>

    <repositories>
        <repository>
            <id>stardog-public</id>
            <url>http://maven.stardog.com</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>com.complexible.stardog</groupId>
            <artifactId>server</artifactId>
            <version>${stardog.version}</version>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>com.complexible.stardog</groupId>
            <artifactId>client-http</artifactId>
            <version>${stardog.version}</version>
            <type>pom</type>
        </dependency>
    </dependencies>


</project>

Thanks Steph, it turned out that I had a broken quartz jar in my .m2 and since I was running the application from within Eclipse I got no error notifications.
When I tried a maven install I saw the problem.
A build system whose usual fix is "clean the local repo" is a mess indeed...
However: now I can build the app and run in from the produced jar but I'm still having troubles with running it from Eclipse: the error I get is this:

There was an error initializing Stardog; one or more dependencies could not be satisfied. Please verify your classpath is correct.
The initialization errors were: 
 *	Error in custom provider, java.lang.RuntimeException: Could not load system index: system
		com.complexible.stardog.virtual.DefaultVirtualGraphRegistry
		com.complexible.stardog.virtual.VirtualGraphService.<init>()
...

it is probably a problem with the Maven Eclipse plugin but maybe I can try to fix it by manually adding some missing deps if you could just point me in the right direction...

It's been a while since anyone here has used Eclipse or the Maven Eclipse plugin, however this sounds like it could be a matter of $STARDOG_HOME being set incorrectly. Either that or since it's complaining about VirtualGraph things perhaps you have a virtual graph defined and Eclipse can't find the JDBC driver?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.