问题描述
- 想用java操作hbase,遇到了些问题
-
新手
在网上看教程,用java在hbase中创建表,输入代码之后问题很多
package hbase;import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.HBaseAdmin;public class hbasetest1 {
private static final String TABLE_NAME = "test1"; private static final String FAMILY_NAME = "cf1"; public static void main(String[] args) throws Exception { // TODO Auto-generated method stub Configuration conf = HBaseConfiguration.create(); conf.set("hbase.rootdir","hdfs://master:9000/hbase"); conf.set("hbase.zookeeper.quorum","master:2181"); HBaseAdmin hBaseAdmin = new HBaseAdmin(conf); HTableDescriptor htableDescriptor = new HTableDescriptor(TABLE_NAME); htableDescriptor.addFamily(new HColumnDescriptor(FAMILY_NAME)); hBaseAdmin.createTable(htableDescriptor); }
}
直接编译运行的话:
log4j:WARN No appenders could be found for logger (org.apache.hadoop.security.Groups).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" org.apache.hadoop.hbase.TableExistsException: test1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.apache.hadoop.ipc.RemoteException.instantiateException(RemoteException.java:106)
at org.apache.hadoop.ipc.RemoteException.unwrapRemoteException(RemoteException.java:95)
at org.apache.hadoop.hbase.util.ForeignExceptionUtil.toIOException(ForeignExceptionUtil.java:45)
at org.apache.hadoop.hbase.client.HBaseAdmin$ProcedureFuture.convertResult(HBaseAdmin.java:4617)
at org.apache.hadoop.hbase.client.HBaseAdmin$ProcedureFuture.waitProcedureResult(HBaseAdmin.java:4575)
at org.apache.hadoop.hbase.client.HBaseAdmin$ProcedureFuture.get(HBaseAdmin.java:4508)
at org.apache.hadoop.hbase.client.HBaseAdmin.createTable(HBaseAdmin.java:674)
at org.apache.hadoop.hbase.client.HBaseAdmin.createTable(HBaseAdmin.java:604)
at hbase.hbasetest1.main(hbasetest1.java:29)
Caused by: org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.hbase.TableExistsException): test1
at org.apache.hadoop.hbase.master.procedure.CreateTableProcedure.prepareCreate(CreateTableProcedure.java:287)
at org.apache.hadoop.hbase.master.procedure.CreateTableProcedure.executeFromState(CreateTableProcedure.java:108)
at org.apache.hadoop.hbase.master.procedure.CreateTableProcedure.executeFromState(CreateTableProcedure.java:58)
at org.apache.hadoop.hbase.procedure2.StateMachineProcedure.execute(StateMachineProcedure.java:119)
at org.apache.hadoop.hbase.procedure2.Procedure.doExecute(Procedure.java:465)
at org.apache.hadoop.hbase.procedure2.ProcedureExecutor.execProcedure(ProcedureExecutor.java:1061)
at org.apache.hadoop.hbase.procedure2.ProcedureExecutor.execLoop(ProcedureExecutor.java:856)
at org.apache.hadoop.hbase.procedure2.ProcedureExecutor.execLoop(ProcedureExecutor.java:809)
at org.apache.hadoop.hbase.procedure2.ProcedureExecutor.access$400(ProcedureExecutor.java:75)
at org.apache.hadoop.hbase.procedure2.ProcedureExecutor$2.run(ProcedureExecutor.java:495)
ant运行:
Buildfile: /home/celine/workspace/test-hbase/build.xml
clean:
[delete] Deleting directory /home/celine/workspace/test-hbase/dist
[delete] Deleting directory /home/celine/workspace/test-hbase/classes
[echo] 清理完毕
init:
[mkdir] Created dir: /home/celine/workspace/test-hbase/classes
[mkdir] Created dir: /home/celine/workspace/test-hbase/dist
compile:
[javac] Compiling 1 source file to /home/celine/workspace/test-hbase/classes
[javac] Note: /home/celine/workspace/test-hbase/src/hbase/hbasetest1.java uses or overrides a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
jar:
[jar] Building jar: /home/celine/workspace/test-hbase/dist/jar.jar
ssh:
[scp] Connecting to 192.168.124.128:22
[scp] done.
sshexec:
[sshexec] Connecting to 192.168.124.128:22
[sshexec] cmd : source /etc/profile; hadoop jar ~/jar.jar hbase.hbasetest1
[sshexec] Exception in thread "main"
[sshexec] java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/HBaseConfiguration
[sshexec] at hbase.hbasetest1.main(Unknown Source)
[sshexec] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[sshexec] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
[sshexec] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[sshexec] at java.lang.reflect.Method.invoke(Method.java:606)
[sshexec] at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
[sshexec] at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
[sshexec] Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hbase.HBaseConfiguration
[sshexec] at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
[sshexec] at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
[sshexec] at java.security.AccessController.doPrivileged(Native Method)
[sshexec] at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
[sshexec] at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
[sshexec] at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
[sshexec] ... 7 moreBUILD FAILED
/home/celine/workspace/test-hbase/build.xml:72: Remote command failed with exit status 1
每次都说远程有问题,但是我在build.xml里面配好了相关信息,不知道为什么sshexec会失败
TAT刚刚开始学,好难,好多问题……
解决方案
Java操作hbase CURD
Java对hbase的操作
java操作hbase
解决方案二:
没事了……我犯了个傻……
解决方案三:
不对。。。远程还是连不上,求解啊啊啊啊啊