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...

asked 09 Mar '12, 11:58

tc_dev's gravatar image

tc_dev
967812
accept rate: 33%


You need to add your CLASSPATH to "java" command:

java -cp "all the jars from your CLASSPATH colon separated":target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App

link

answered 09 Mar '12, 12:10

yufeldman's gravatar image

yufeldman ♦♦
1.9k27
accept rate: 25%

Thanks, this worked!

Did not realize CLASSPATH environment variable is not picked up automatically. Have not done Java in a very long time!

(09 Mar '12, 12:17) tc_dev
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×78
×37
×2

Asked: 09 Mar '12, 11:58

Seen: 1,641 times

Last updated: 09 Mar '12, 12:17

powered by OSQA