为什么我在java中读取graphml时会出现这个错误?

时间:2018-02-22 05:15:58

标签: java classnotfoundexception tinkerpop graphml

我试图通过其父子关系读取图形并将其转换为xml文件,但是在读取图形时我得到以下错误,尽管我已经添加了tinkerpop所需的所有依赖项。来自eclipse的堆栈跟踪是:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tinkerpop/shaded/kryo/Serializer
at org.apache.tinkerpop.gremlin.structure.io.gryo.GryoVersion.initV1d0Registrations(GryoVersion.java:387)
at org.apache.tinkerpop.gremlin.structure.io.gryo.GryoVersion.<clinit>(GryoVersion.java:159)
at org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph.io(TinkerGraph.java:200)
at MavenTinkerPop.TinkerPop.GremlinGraphConvertor.getFinalList(GremlinGraphConvertor.java:25)
at MavenTinkerPop.TinkerPop.XMLPass.main(XMLPass.java:22)
Caused by: java.lang.ClassNotFoundException: org.apache.tinkerpop.shaded.kryo.Serializer
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 5 more

我尝试了很多,但我无法找到解决方案,这是我的实际代码:

public class GremlinGraphConvertor {

    private static List<String> realList = new ArrayList<>();
    private static List<String> intermediateList = new ArrayList<>();

    public static List<String> getFinalList() throws IOException {

        String graphmlFile = "GraphLineage.graphml";

        final Graph newGraph = TinkerGraph.open();

        try {
            newGraph.io(IoCore.graphml()).readGraph(graphmlFile);
        } catch (IOException e) {
            e.printStackTrace();
        }

        GraphTraversalSource n = newGraph.traversal();

        List<Path> nodes=n.V().has("name").outE().inV().path().toList() ;       
        Iterator<Path> iterator = nodes.iterator();
        String splitBy = ",";

        while (iterator.hasNext()) {
                String Str1=iterator.next().toString();
                Str1=Str1.replaceAll("\\[|v\\[|e\\[|\\]","");
                intermediateList.add(Str1 + "\n");
            }

            for(String line : intermediateList){ 
                String[] vertices = line.split(splitBy);
                String SourceVer=vertices[0].trim();
                String TargetVer=vertices[2].trim();
                String Edge=vertices[1].trim();
                String Output=SourceVer+","+TargetVer+","+n.V(SourceVer).has("name").values("name","type").toList().toString().replaceAll("\\[|\\]", "")+","+n.V(TargetVer).has("name").values("name","type").toList().toString().replaceAll("\\[|\\]", "")+","+Edge+",";
                String Sourceplug=n.V(SourceVer).has("stepType").has("pluginId").values("stepType","pluginId").toList().toString().replaceAll("\\[|\\]","").concat(",");
                String Targetplug=n.V(TargetVer).has("stepType").has("pluginId").values("stepType","pluginId").toList().toString().replaceAll("\\[|\\]","");
                if(Sourceplug.length() == 1)
                 {
                    Sourceplug="N/A,N/A,";
                 }
                if(Targetplug.length() == 0)
                 {
                    Targetplug="N/A,N/A,";
                 }
                Output=Output.concat(Sourceplug).concat(Targetplug);
                realList.add(Output + "\n");
            }
        return realList;

    }

}

0 个答案:

没有答案