线程“main”中的异常java.lang.NoSuchMethodError:org.openrdf.query.algebra.Var.isConstant()Z

时间:2015-11-27 11:50:38

标签: java maven neo4j tinkerpop

我正在尝试运行简单的Tinkerpop代码

import info.aduna.iteration.CloseableIteration;

import org.openrdf.model.Statement;
import org.openrdf.model.ValueFactory;
import org.openrdf.query.BindingSet;
import org.openrdf.query.QueryEvaluationException;
import org.openrdf.query.impl.EmptyBindingSet;
import org.openrdf.query.parser.ParsedQuery;
import org.openrdf.query.parser.sparql.SPARQLParser;
import org.openrdf.sail.Sail;
import org.openrdf.sail.SailConnection;
import org.openrdf.sail.SailException;

import com.tinkerpop.blueprints.impls.neo4j.Neo4jGraph;
import com.tinkerpop.blueprints.impls.tg.TinkerGraph;
import com.tinkerpop.blueprints.oupls.sail.GraphSail;

public class Main {
   public static void main(String args[]) {

    try {

        TinkerGraph graph = new TinkerGraph();

        //Neo4jGraph graphh = new Neo4jGraph("C://Users//ZXZ//Desktop//neo4j");

        Sail sail = new GraphSail(graph);

        sail.initialize();
        ValueFactory vf = sail.getValueFactory();
        SailConnection sc = sail.getConnection();
        sc.begin();

        sc.addStatement(vf.createURI("http://tinkerpop.com#1"),
                vf.createURI("http://tinkerpop.com#knows"),
                vf.createURI("http://tinkerpop.com#3"),
                vf.createURI("http://tinkerpop.com"));
        sc.addStatement(vf.createURI("http://tinkerpop.com#1"),
                vf.createURI("http://tinkerpop.com#name"),
                vf.createLiteral("marko"),
                vf.createURI("http://tinkerpop.com"));
        sc.addStatement(vf.createURI("http://tinkerpop.com#3"),
                vf.createURI("http://tinkerpop.com#name"),
                vf.createLiteral("josh"),
                vf.createURI("http://tinkerpop.com"));

        System.out.println("get statements: ?s ?p ?o ?g");
        CloseableIteration<? extends Statement, SailException> results = sc
                .getStatements(null, null, null, false);
        while (results.hasNext()) {
            System.out.println(results.next());
        }

        System.out
                .println("\nget statements: http://tinkerpop.com#3 ?p ?o ?g");
        results = sc.getStatements(vf.createURI("http://tinkerpop.com#3"),
                null, null, false);
        while (results.hasNext()) {
            System.out.println(results.next());
        }

        System.out
                .println("************************************************************************");

        SPARQLParser parser = new SPARQLParser();
        CloseableIteration<? extends BindingSet, QueryEvaluationException> sparqlResults;
        String queryString = "SELECT ?x ?y WHERE { ?x <http://tinkerpop.com#knows> ?y }";
        ParsedQuery query = parser.parseQuery(queryString,
                "http://tinkerPop.com");

        System.out.println("\nSPARQL: " + queryString);
        sparqlResults = sc.evaluate(query.getTupleExpr(),
                query.getDataset(), new EmptyBindingSet(), false);

        while (sparqlResults.hasNext()) {
            System.out.println(sparqlResults.next());
        }

        sc.rollback();
        sc.close();
        graph.shutdown();
        sail.shutDown();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

}

但要遵循 EXCEPTION

  

线程“main”中的异常java.lang.NoSuchMethodError:org.openrdf.query.algebra.Var.isConstant()Z       在org.openrdf.query.algebra.evaluation.impl.EvaluationStrategyImpl $ 3.convert(EvaluationStrategyImpl.java:542)       在org.openrdf.query.algebra.evaluation.impl.EvaluationStrategyImpl $ 3.convert(EvaluationStrategyImpl.java:536)       在info.aduna.iteration.ConvertingIteration.next(ConvertingIteration.java:88)       在info.aduna.iteration.ConvertingIteration.next(ConvertingIteration.java:88)       在info.aduna.iteration.IterationWrapper.next(IterationWrapper.java:82)       在db.db.Main.main(Main.java:78)

这是我的pom:

<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>db</groupId>
<artifactId>db</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>db</name>
<url>http://maven.apache.org</url>

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

<repositories>
    <repository>
        <id>central</id>
        <name>Maven Repository Switchboard</name>
        <layout>default</layout>
        <url>http://repo1.maven.org/maven2</url>
    </repository>
    <repository>
        <id>neo4j-public-repository</id>
        <name>Publically available Maven 2 repository for Neo4j</name>
        <url>http://m2.neo4j.org</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>aduna-repo</id>
        <name>Aduna repository</name>
        <url>http://repo.aduna-software.org/maven2/releases</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>com.tinkerpop.blueprints</groupId>
        <artifactId>blueprints-neo4j-graph</artifactId>
        <version>2.6.0</version>
    </dependency>

    <dependency>
        <groupId>com.tinkerpop.blueprints</groupId>
        <artifactId>blueprints-graph-sail</artifactId>
        <version>2.6.0</version>
    </dependency>

    <dependency>
        <groupId>org.openrdf.sesame</groupId>
        <artifactId>sesame-repository-sail</artifactId>
        <version>2.7.0</version>
    </dependency>


    <dependency>
        <groupId>org.openrdf.sesame</groupId>
        <artifactId>sesame-rio-rdfxml</artifactId>
        <version>2.7.0</version>
    </dependency>

    <dependency>
        <groupId>org.openrdf.sesame</groupId>
        <artifactId>sesame-queryparser-sparql</artifactId>
        <version>2.7.0</version>
    </dependency>

</dependencies>

例外的原因是什么?

1 个答案:

答案 0 :(得分:0)

我非常确定这条线是做什么的:

CloseableIteration<? extends BindingSet, QueryEvaluationException> sparqlResults;

特别是这一行,

<? extends BindingSet, QueryEvaluationException>

试着看看那里,你可以解决这个问题。