My hbase java code to create table
public class CreateTable {
public static void main( String args[] ) throws IOException {
HBaseConfiguration hc = new HBaseConfiguration( new Configuration( ) );
HTableDescriptor ht = new HTableDescriptor( "cdrs" );
ht.addFamily( new HColumnDescriptor( "number:" ) );
ht.addFamily( new HColumnDescriptor( "company:" ) );
ht.addFamily( new HColumnDescriptor( "time:" ) );
ht.addFamily( new HColumnDescriptor( "location:" ) );
HBaseAdmin hba = new HBaseAdmin( hc );
System.out.println( "creating table..." );
hba.createTable( ht );
System.out.println( "done!" );
}
running the jar of the code i am getting :- hadoop jar hbase-0.0.1-SNAPSHOT.jar apache.hbase.CreateTable
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop /hbase/HBaseConfiguration
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.apache.hadoop.util.RunJar.run(RunJar.java:227)
at org.apache.hadoop.util.RunJar.main(RunJar.java:148)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hbase.HBaseConfiguration
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 4 more
i am new to hadoop and hbase and facing problem to run this jar from past several days ..any help would be appreciated
Have you included the hbase-common dependency? If you are using maven, it will get downloaded as a transitive dependency when you include hbase-client.
Package: org.apache.hadoop.hbase
Also, new HBaseConfiguration(...params...) is now deprecated and instead, you should use HBaseConfiguration.create();
Configuration config = HBaseConfiguration.create();
config.setInt("timeout", timeout);
config.set("hbase.zookeeper.quorum",zkAddress);
config.set("hbase.zookeeper.property.clientPort", zkPort);
config.set("hbase.client.retries.number", nRetries);//check for configs applicable or use hbase-site and core-site configs
Connection connection = ConnectionFactory.createConnection(config);
在新的hbase版本上使fat jar出现问题,不建议使用jar并具有很多依赖性。因此我在hbase-client-1.2.6-jar
添加了hbase-client-1.2.6-jar
和hbase-common-1.2.6-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.