AnsweredAssumed Answered

HBase Java API: java.lang.NoClassDefFoundError

Question asked by tc_dev on Mar 9, 2012
Latest reply on Mar 9, 2012 by tc_dev
I am prototyping a Java/Maven project that needs to directly access HBase. HBase installed successfully and I created tables via shell using examples in the documentation.

I am able to run "mvn package" to build my project, however when trying to run it the HBase class loading always fails. I isolated the problem by simplifying the failing line / exception -

        ClassLoader loader = HBaseConfiguration.class.getClassLoader();

Exception in thread "main" java.lang.NoClassDefFoundError: org.apache.hadoop.hbase.HBaseConfiguration 
        at com.mycompany.app.App.class$(App.java:26) 
        at com.mycompany.app.App.main(App.java:26) 

This seems wrong since I believe CLASSPATH is set correctly before running the project -

export HADOOP\_CLASSPATH=\`hadoop classpath\` 
export HBASE\_CLASSPATH=\`/opt/mapr/hbase/hbase-0.90.4/bin/hbase classpath\` 
export CLASSPATH=$HADOOP\_CLASSPATH:$HBASE\_CLASSPATH 
echo $CLASSPATH 
java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App

Here is the dependency section from my pom.xml

    <dependency> 
      <groupId>org.apache.hadoop</groupId> 
      <artifactId>hbase</artifactId>  
      <version>0.90.4</version>  
      <scope>system</scope>  
      <systemPath>/root/.m2/repository/hbase/hbase/0.90.4/hbase-0.90.4.jar</systemPath>   
    </dependency>   

    <dependency>  
      <groupId>org.apache.hadoop</groupId>  
      <artifactId>hadoop-core</artifactId> 
      <version>0.20.2</version> 
      <scope>system</scope> 
      <systemPath>/root/.m2/repository/hadoop/hadoop/0.20.2/hadoop-0.20.2.jar</systemPath>   
    </dependency>    

Why is my code failing? The dependencies worked at compile time...

Outcomes