简体   繁体   中英

HBase - java.lang.NoClassDefFoundError in java

Im just trying to interact with Hbase using Java

    import org.apache.hadoop.conf.Configuration;
    import org.apache.hadoop.hbase.*;
    import org.apache.hadoop.hbase.client.*;
    import org.apache.hadoop.hbase.util.*;
    import org.apache.hadoop.hbase.HBaseConfiguration;

    public class TestHBase {
        public static void main(String[] args) throws Exception {
            Configuration conf = HBaseConfiguration.create();
            HBaseAdmin admin = new HBaseAdmin(conf);
            try {
                HTable table = new HTable(conf, "test-table");
                Put put = new Put(Bytes.toBytes("test-key"));
                put.add(Bytes.toBytes("cf"), Bytes.toBytes("q"), Bytes.toBytes("value"));
                table.put(put);
            } finally {
                admin.close();
            }
        }
    }

Above is my program and My TestHBase folder contains the following items

hbase-0.94.6.1.3.0.0-0380.jar
TestHBase.class

And i have created jar using the following code

java>jar -cvf TestHBase.jar -C TestHBase/ .

And i have run my jar using the following code

Hadoop> Hadoop jar C:\java\bin\TestHBase.jar  com.bgt.TestHBase

But im getting the following error

C:\HDP>hadoop jar C:\java\jdk1.6.0_31\bin\zip.jar com.bgt.TestHBase
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/hba
se/HBaseConfiguration
        at com.bgt.TestHBase.main(TestHBase.java:12)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.hadoop.util.RunJar.main(RunJar.java:160)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hbase.HBaseConfig
uration
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        ... 6 more

Can anyone help me

Thanks

It's Hbase client Java Program, you should not run it with "hadoop". It's should be a standard jar program running style, like: java -jar yourjar .jar

When you use ">jar -cvf TestHBase.jar -C TestHBase/ .", it doesn't garantee the jar dependencies can be found during runtime, which you face it.

In eclipse, the jar export function has a choice of "Runable" jar.

So suggest you run your testing class seprately with explicitly point out the dependent jar.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM