0

I am using janusgraph, with storage backend HBase. Currently I am trying to add vertices to the database. The part of the code is

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();
  }
}

with the main function calls

Graph.addVertex();

The error is

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

I am using janusgraph 0.2.0, in maven 0.2.0

and hbase 1.2.0, java 1.8

I set storage-hostname=127.0.0.1 in jg.properties, so is it a dependency error? Where is exactly the MasterNotRunning?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Litchy
  • 355
  • 1
  • 4
  • 18
  • janusgraph 0.3 is not released yet. Please downgrade to 0.2 according to [version-compat](https://mbrukman.github.io/docs.janusgraph.org/0.3.0-SNAPSHOT/version-compat.html) – Rcordoval Jun 21 '18 at 07:35
  • @Rcordoval I changed it to `0.2.0` and the same problem remains – Litchy Jun 21 '18 at 08:22
  • Looks like you are missing the janusgraph-hbase jar file – nos Jun 21 '18 at 08:38
  • @Litchy look at this [pom.xml](https://github.com/JanusGraph/janusgraph/blob/e1b087566bbc85ecfadaef9455c4f8358ae88947/janusgraph-hadoop-parent/janusgraph-hadoop-2/pom.xml) – Rcordoval Jun 21 '18 at 08:41
  • @nos I added `janusgraph-hbase` and the error becomes `java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/MasterNotRunningException`, I set `storage-hostname=127.0.0.1`, how could this happen?.. – Litchy Jun 21 '18 at 09:00
  • 1
    `Could not find implementation class` means: A java class is instantiated by reflection (see java.lang.*reflect*.InvocationTargetException in stack trace) at runtime. If the class is not present (class or containing jar not in classpath) then you will get this error. – Würgspaß Jun 21 '18 at 09:01
  • @Litchy There seems to be another dependency to `org/apache/hadoop/*` that you have to resolve. – Würgspaß Jun 21 '18 at 09:03
  • @Würgspaß I also added another `janusgraph-hadoop` and the problem remains. I have updated the error and the dependencies up to now above – Litchy Jun 21 '18 at 09:04
  • After adding the dependencies the error becomes class not found of `MasterNotRunning` – Litchy Jun 21 '18 at 09:05
  • @Litchy If org/apache/hadoop/ is missing, you are missing some hadoop jar files. Are you using some form of dependency management (e.g. maven) ? If you are doing all this manually, you have quite a bit of job in front of you to track down all the correct dependencies and the proper versions of jar files that work together. – nos Jun 21 '18 at 09:07
  • @nos I am using maven, adding dependencies `janusgraph-core,janusgraph-hbase,janusgraph-hadoop`, after adding `janusgraph-hbase` the error becomes above – Litchy Jun 21 '18 at 09:11
  • @Rcordoval do you mean that I need to add all the dependencies in this `pom.xml` to my `pom.xml`? – Litchy Jun 21 '18 at 09:15
  • no, cross check versions... – Rcordoval Jun 22 '18 at 03:59

1 Answers1

0

I have found the solution, but still curious.

I search the class MasterNotRunning and found this is in package org.apache.hadoop.hbase and finally make a guess to add org.apache.hbase & hbase-client into dependency. And the error disappears.

However, I still could not find the reason of this error. If some code in dependency jar uses the class MasterNotRunning then it should import the hbase-client jar, then this should be already in the dependency. How can this code pass the compiling and finally throws an exception during the running time.

Just add, I uses export->runnable jar file to get my jar, so all the dependencies should be added into it.

Litchy
  • 355
  • 1
  • 4
  • 18