如何修复'java.lang.NoClassDefFoundError:org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource $ GraphTraversalSourceStub'? [英] How to fix 'java.lang.NoClassDefFoundError: org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource$GraphTraversalSourceStub'?

查看:139
本文介绍了如何修复'java.lang.NoClassDefFoundError:org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource $ GraphTraversalSourceStub'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用TinkerGraph初始化内存中的图形.

I am trying to initialize an in-memory graph using TinkerGraph.

首先,我在上下文xml文件中定义了bean,并尝试初始化TinkerGraph.

Firstly, i have defined the bean in my context xml file and tried to initialise the TinkerGraph.

我的目的是对我创建的用于形成gremlin查询的类进行单元测试,我从这些类中获得的最终查询采用字符串形式,因此为了通过TinkerGraph执行它们,我必须使用了以下文章中给出的方法:以字符串形式获取Gremlin查询并在Java中执行它,而无需将其提交给GremlinServer

My intention is to unit test the classes that i have created for forming the gremlin queries, the end queries that i get from these classes are in the form of a string, so in order to execute them through the TinkerGraph, i have the used the approach given in the following post: Get Gremlin query as a String and execute it in java without submitting it to the GremlinServer

我还想知道我是否将首选方法用于运行gremlin查询作为单元测试的一部分?

I would also like to know whether the approach that i have taken is the preferred approach, for running the gremlin queries as part of the unit testing?

以下是我包含在pom.xml中的依赖项:

Following are the dependencies i have included in the pom.xml:

<dependency>
    <groupId>org.apache.tinkerpop</groupId>
    <artifactId>tinkergraph-gremlin</artifactId>
    <version>3.2.4</version>
</dependency>

<dependency>
      <groupId>org.apache.tinkerpop</groupId>
      <artifactId>gremlin-groovy</artifactId>
      <version>3.0.2-incubating</version>
</dependency>

EmbeddedGremlinQueryEngine如下:

EmbeddedGremlinQueryEngine is as follows:


import org.apache.tinkerpop.gremlin.driver.Result;
import org.apache.tinkerpop.gremlin.driver.ResultSet;
import org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.script.Bindings;
import javax.script.ScriptEngine;
import javax.script.ScriptException;
import java.util.List;

public class UcsEmbeddedGremlinQueryEngine implements GremlinEngine{

    private static final Logger logger = LoggerFactory.getLogger(UcsEmbeddedGremlinQueryEngine.class);
    private GraphTraversalSource graphTraversalSource = null;
    private Graph graph = null;
    private ScriptEngine engine = null;
    private Bindings bindings = null;

    public UcsEmbeddedGremlinQueryEngine() {
        graph = TinkerGraph.open();
        graphTraversalSource = graph.traversal();
        engine = new GremlinGroovyScriptEngine();
        bindings = engine.createBindings();
        bindings.put("g", graphTraversalSource);
    }

    public void shutdown() throws Exception {
        if (graph != null){
            graph.close();
        }
        logger.info("TinkerGraph shutdown complete.");
    }

    @Override
    public List<Result> query(String query) {
        List<Result> res = null;
        try {
            ResultSet results = (ResultSet) engine.eval(query, bindings);
            res = results.all().join();

            for (Result r : res) {
                System.out.println("result: " + r + '\n');
            }

        } catch (ScriptException e) {
            e.printStackTrace();
        }
        return res;
    }

    // This function reads the initScript and run them as gremlin queries.
    public synchronized void initialize() {
        logger.debug("Initializing embedded TinkerGraph. This will only take a few seconds....");
        //TODO include the execution of queries as part of initialisation
    }
}

堆栈跟踪如下:

java.lang.NoClassDefFoundError: org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource$GraphTraversalSourceStub
    at org.apache.tinkerpop.gremlin.groovy.loaders.StepLoader.load(StepLoader.groovy:54)
    at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod(IndyInterface.java:236)
    at org.apache.tinkerpop.gremlin.groovy.loaders.GremlinLoader.load(GremlinLoader.groovy:28)
    at org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine.<init>(GremlinGroovyScriptEngine.java:189)
    at org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine.<init>(GremlinGroovyScriptEngine.java:172)
    at com.intuit.gro.mcsdata.gemlinengine.UcsEmbeddedGremlinQueryEngine.<init>(UcsEmbeddedGremlinQueryEngine.java:28)

EmbeddedGremlinQueryEngine被定义为xml文件中的一个bean,当该bean被加载时,我得到如下错误:构造函数抛出异常;嵌套的异常是java.lang.NoClassDefFoundError:org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource $ GraphTraversalSourceStub

EmbeddedGremlinQueryEngine is defined as a bean in the xml file, when the bean is loaded i get the error as Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource$GraphTraversalSourceStub

我不知道GraphTraversalSourceStub在初始化期间是如何出现的,我无法找到有关它的任何信息.任何帮助将不胜感激.

I don't understand how the GraphTraversalSourceStub comes into picture during initialization, I was not able to find any information about it. Any help would be appreciated.

推荐答案

我认为您的问题是您在:

I think your problem is that you're:

  1. 使用确实很老的TinkerPop版本
  2. 您使用的旧版本可能不兼容

我不确定您是否有使用3.2.4的理由,但是如果是这样,请确保gremlin-groovy也是3.2.4.请注意,目前基本上未维护3.2.x代码行,最新版本为6个月前的3.2.11.如果您正在开发新的应用程序,那么我强烈建议您简单地使用几周前发布的最新版本3.4.2.

I'm not sure if you have a reason for using 3.2.4, but if so, make sure gremlin-groovy is also 3.2.4. Note that the 3.2.x line of code is largely not maintained at this point with the last release being 3.2.11 about 6 months ago. If you are developing a new application then I highly recommend that you simply utilize the latest version of 3.4.2 which released a few weeks ago.

关于您的测试方法,我想很好.如果您已经测试了Gremlin字符串,那么除了使用Gremlin Server之外,您实际上没有其他选择.显然,为 GremlinGroovyScriptEngine 提供测试工具非常容易.

As for your testing approach, I suppose that's fine. If you have test Gremlin strings then you really don't have much other choice in the matter, short of using Gremlin Server. Obviously providing a test harness for GremlinGroovyScriptEngine is a lot easier to do.

这篇关于如何修复'java.lang.NoClassDefFoundError:org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource $ GraphTraversalSourceStub'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆