使用 janusgraph 后端 HBase 时 MasterNotRunning 的 NoClassDefFound

NoClassDefFound of MasterNotRunning when using janusgraph backend HBase

我正在使用带有存储后端 HBase 的 janusgraph。目前我正在尝试将顶点添加到数据库中。部分代码为

public class Graph {
  private static JanusGraph graph = JanusGraphFactory.open("conf/jg.properties");

  public static JanusGraph getGraph() {
    return graph;
  } 
  public static void addVertex() {
    for (int i=0; i<5; i++) {
        graph.addVertex("test", i);
    }       
    graph.tx().commit();
  }
}

用主函数调用

Graph.addVertex();

错误是

Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)

Caused by: java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/MasterNotRunningException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.janusgraph.util.system.ConfigurationUtil.instantiate(ConfigurationUtil.java:56)
at org.janusgraph.diskstorage.Backend.getImplementationClass(Backend.java:477)
at org.janusgraph.diskstorage.Backend.getStorageManager(Backend.java:409)
at org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.<init>(GraphDatabaseConfiguration.java:1376)
at org.janusgraph.core.JanusGraphFactory.open(JanusGraphFactory.java:164)
at org.janusgraph.core.JanusGraphFactory.open(JanusGraphFactory.java:133)
at org.janusgraph.core.JanusGraphFactory.open(JanusGraphFactory.java:80)    
... 5 more
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hbase.MasterNotRunningException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 16 more

我在 maven 中使用 janusgraph 0.2.0 0.2.0

和 hbase 1.2.0,java1.8

我在jg.properties中设置了storage-hostname=127.0.0.1,请问是依赖错误吗? MasterNotRunning 到底在哪里?

我找到了解决办法,但还是很好奇。

我搜索了 class MasterNotRunning,发现它在包 org.apache.hadoop.hbase 中,最后猜测将 org.apache.hbase & hbase-client 添加到依赖项中。然后错误消失了。

但是,我还是找不到这个错误的原因。如果依赖 jar 中的某些代码使用 class MasterNotRunning 那么它应该导入 hbase-client jar,那么它应该已经在依赖中了。这段代码怎么能编译通过,最后在运行时间抛出异常。

补充一下,我使用export->runnable jar file来获取我的jar,所以所有的依赖都应该添加进去。