这是我的javahbase createtable程序below:-
public class createtable
{
public static void main(String[] args) throws IOException
{
Configuration conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum", "sandbox.hortonworks.com");
conf.set("hbase.zookeeper.property.clientPort", "2181");
conf.set("zookeeper.znode.parent", "/hbase-unsecure");
HBaseAdmin admin = new HBaseAdmin(conf);
HTableDescriptor tableDescriptor = new HTableDescriptor(TableName.valueOf("people"));
tableDescriptor.addFamily(new HColumnDescriptor("personal"));
tableDescriptor.addFamily(new HColumnDescriptor("contactinfo"));
admin.createTable(tableDescriptor);
Put put = new Put(Bytes.toBytes("doe-john-m-12345");
}
在运行命令hadoop jar table-0.0.1-snapshot.jar table.createtable时创建程序的jar(table-0.0.1-snapshot.jar)之后
我要走了
Exception in thread "main" java.lang.NoClassDefFoundError:org/apachehadoop/hbase/HBaseConfiguration at
table.createtable.main(createtable.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav a:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.hadoop.util.RunJar.run(RunJar.java:234)
at org.apache.hadoop.util.RunJar.main(RunJar.java:148) Causedby:
java.lang.ClassNotFoundException:org.apache.hadoop.hbase.HBase
Configuration
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
how do i resolve this error ??
3条答案
按热度按时间9udxz4iz1#
请阅读此博客:https://my-bigdata-blog.blogspot.com/2017/08/hbase-programming-on-map-reduce-with.html
有两点要做
1) 代码应该有tablemapreduceutil.adddependencyjars(作业);
2) 在命令行上-执行命令之前,请执行以下操作:
export hadoop\u classpath=您的jar路径
export hadoop\u classpath=$hadoop\u classpath:
hbase classpath
这将添加要执行的hbase库。在maven/netbeans中添加的是用于编译的。pjngdqdw2#
我解决了这个问题,因为在制作fat jar时有问题,而且新的hbase版本jar中有许多依赖项,因此我还向eclipse外部添加了hbase-client-1.2.6-jar和hbase-common-1.2.6-jar,然后构建fat jar……这解决了我的问题。
lc8prwob3#
您的代码无法看到hbase.jar。请尝试在pom.xml中添加此片段
然后运行它。