package lsq.HelloHBase;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.*;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;
import org.mortbay.log.Log;
public class Chapter4 {
public static Configuration configuration;
public static Connection connection;
public static Admin admin;
public static void main(String[] args) throws IOException {
createTable("student",new String[] {"score"});
insertData("student","Jack","score","English","69");
insertData("student","Jack","score","Math","86");
insertData("student","Jack","score","Computer","77");
getData("student","Jack","score","English");
}
@SuppressWarnings("deprecation")
public static void init() {
configuration = HBaseConfiguration.create();
//configuration.setConfiguration("hbase.rootdir","hdfs://idx046:9000/hbase");
try {
//connection = ConnectionFactory.createConnection(configuration);
connection = ConnectionFactory.createConnection();
admin = connection.getAdmin();
}catch(IOException e) {
e.printStackTrace();
}
}
public static void close() {
try {
if (admin!=null) {
admin.close();
}
if (null != connection ) {
connection.close();
}
}catch(IOException e) {
e.printStackTrace();
}
}
public static void createTable(String myTableName, String[] colFamily) throws IOException {
init();
TableName tableName = TableName.valueOf(myTableName);
if ( admin.tableExists(tableName )) {
System.out.println("table exists!");
}else {
@SuppressWarnings("deprecation")
HTableDescriptor hTableDescriptor = new HTableDescriptor(tableName);
for (String str: colFamily) {
HColumnDescriptor hColumnDescriptor = new HColumnDescriptor(str);
hTableDescriptor.addFamily(hColumnDescriptor);
}
admin.createTable(hTableDescriptor);
}
close();
}
public static void insertData(String tableName,String rowkey,String colFamily, String col, String value) throws IOException {
init();
Table table = connection.getTable(TableName.valueOf(tableName));
Put put = new Put(Bytes.toBytes(rowkey));
put.addColumn(Bytes.toBytes(colFamily), Bytes.toBytes(col),Bytes.toBytes(value));
table.put(put);
table.close();
close();
}
public static void getData(String tableName,String rowkey,String colFamily, String col ) throws IOException {
init();
Table table = connection.getTable(TableName.valueOf(tableName));
Get get = new Get(Bytes.toBytes(rowkey));
get.addColumn(Bytes.toBytes(colFamily), Bytes.toBytes(col) );
Result result = table.get(get);
String msg = new String(result.getValue(colFamily.getBytes(),col==null?null:col.getBytes()));
System.out.println(msg);
Log.info(msg );
table.close();
close();
}
}
/*
[lsq@idx046 ~/data]$ hadoop jar HelloHBase-0.0.1-SNAPSHOT.jar lsq.HelloHBase.Chapter4
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/client/TableDesc
riptor at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.apache.hadoop.util.RunJar.run(RunJar.java:214)
at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hbase.client.TableDescriptor
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
原因: 缺少 org/apache/hadoop/hbase/client/ ??
编辑 pom.xml , 添加依赖包复制:
OK
*/
/*
[lsq@idx046 ~/data]$ hadoop jar HelloHBase-0.0.1-SNAPSHOT.jar lsq.HelloHBase.Chapter4
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hbase/thirdparty/com/google/c
ommon/cache/CacheLoader at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java
:202) at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java
:114) at lsq.HelloHBase.Chapter4.init(Chapter4.java:31)
at lsq.HelloHBase.Chapter4.createTable(Chapter4.java:50)
at lsq.HelloHBase.Chapter4.main(Chapter4.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
Caused by: java.lang.ClassNotFoundException: org.apache.hbase.thirdparty.com.google.common.cache.Ca
cheLoader at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 11 more
错误: 缺少 org/apache/hbase/thirdparty/com/google/common/cache/ ??
参考: 检查一下是否有guava.jar这个包?或者存在多个版本?
查找: --NOTICES.txt:
This product includes guava
Licensed under Apache License, Version 2.0, see LICENSE for details.
incorporated from com.google.guava:guava:jar:11.0.2
For source see 'http://code.google.com/p/guava-libraries/guava/guava'.
--
编辑 pom.xml, 添加依赖包 :
com.google.guava:guava:jar:11.0.2
OK !
*/
/*
[lsq@idx046 ~/data]$ hadoop jar HelloHBase-0.0.1-SNAPSHOT.jar lsq.HelloHBase.Chapter4
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hbase/thirdparty/com/google/c
ommon/util/concurrent/ListeningExecutorService at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java
:202) at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java
:114) at lsq.HelloHBase.Chapter4.init(Chapter4.java:31)
at lsq.HelloHBase.Chapter4.createTable(Chapter4.java:50)
at lsq.HelloHBase.Chapter4.main(Chapter4.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
Caused by: java.lang.ClassNotFoundException: org.apache.hbase.thirdparty.com.google.common.util.con
current.ListeningExecutorService at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 11 more
错误: 缺少 org/apache/hbase/thirdparty/ ???
查看 NOTICES.txt , 编辑 pom.xml 添加依赖包:
org.apache.hbase.thirdparty:hbase-shaded-miscellaneous:jar:2.1.0
org.apache.hbase.thirdparty:hbase-shaded-netty:jar:2.1.0
org.apache.hbase.thirdparty:hbase-shaded-protobuf:jar:2.1.0
OK!
*/
/*
[lsq@idx046 ~/data]$ hadoop jar HelloHBase-0.0.1-SNAPSHOT.jar lsq.HelloHBase.Chapter4
18/10/30 09:17:20 DEBUG util.NativeCodeLoader: Trying to load the custom-built native-hadoop librar
y...18/10/30 09:17:20 DEBUG util.NativeCodeLoader: Loaded the native-hadoop library
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/shaded/protobuf/
generated/MasterProtos$MasterService$BlockingInterface at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java
:210) at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java
:114) at lsq.HelloHBase.Chapter4.init(Chapter4.java:31)
at lsq.HelloHBase.Chapter4.createTable(Chapter4.java:50)
at lsq.HelloHBase.Chapter4.main(Chapter4.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hbase.shaded.protobuf.generated.Mast
erProtos$MasterService$BlockingInterface at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 24 more
[lsq@idx046 ~/data]$
错误: 缺少 org/apache/hadoop/hbase/shaded/protobuf/ ???
查看 NOTICES.txt 编辑 pom.xml 添加依赖包: org.apache.hbase:hbase-protocol-shaded:jar:2.1.0
OK !
*/
/*
[lsq@idx046 ~/data]$ hadoop jar HelloHBase-0.0.1-SNAPSHOT.jar lsq.HelloHBase.Chapter4
18/10/30 09:22:22 DEBUG util.NativeCodeLoader: Trying to load the custom-built native-hadoop librar
y...18/10/30 09:22:22 DEBUG util.NativeCodeLoader: Loaded the native-hadoop library
java.io.IOException: java.lang.reflect.InvocationTargetException
at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java
:221) at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java
:114) at lsq.HelloHBase.Chapter4.init(Chapter4.java:31)
at lsq.HelloHBase.Chapter4.createTable(Chapter4.java:50)
at lsq.HelloHBase.Chapter4.main(Chapter4.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java
:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorI
mpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java
:219) ... 10 more
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/lang3/ArrayUtils
at org.apache.hadoop.hbase.HConstants.
at org.apache.hadoop.hbase.client.ConnectionUtils.getPauseTime(ConnectionUtils.java:82)
at org.apache.hadoop.hbase.client.AsyncProcess.
at org.apache.hadoop.hbase.client.ConnectionImplementation.
java:265) ... 15 more
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang3.ArrayUtils
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 19 more
Exception in thread "main" java.lang.NullPointerException
at lsq.HelloHBase.Chapter4.createTable(Chapter4.java:52)
at lsq.HelloHBase.Chapter4.main(Chapter4.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
[lsq@idx046 ~/data]$
错误 : Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang3.ArrayUtils
查看 NOTICES.txt 编辑 pom.xml 添加依赖包:org.apache.commons:commons-lang3:jar:3.6
OK !
*/
/*
18/10/30 10:24:01 INFO zookeeper.ZooKeeper: Client environment:java.library.path=/panks/data02/lsq/
idx030/app/hadoop-2.7.3/lib/native18/10/30 10:24:01 INFO zookeeper.ZooKeeper: Client environment:java.io.tmpdir=/tmp
18/10/30 10:24:01 INFO zookeeper.ZooKeeper: Client environment:java.compiler=
18/10/30 10:24:01 INFO zookeeper.ZooKeeper: Client environment:os.name=Linux
18/10/30 10:24:01 INFO zookeeper.ZooKeeper: Client environment:os.arch=amd64
18/10/30 10:24:01 INFO zookeeper.ZooKeeper: Client environment:os.version=2.6.32-358.el6.x86_64
18/10/30 10:24:01 INFO zookeeper.ZooKeeper: Client environment:user.name=lsq
18/10/30 10:24:01 INFO zookeeper.ZooKeeper: Client environment:user.home=/u/lsq
18/10/30 10:24:01 INFO zookeeper.ZooKeeper: Client environment:user.dir=/panks/data02/lsq/idx030/da
ta18/10/30 10:24:01 INFO zookeeper.ZooKeeper: Initiating client connection, connectString=idx046:2181
sessionTimeout=90000 watcher=org.apache.hadoop.hbase.zookeeper.ReadOnlyZKClient$$Lambda$12/259950055@4c285d8118/10/30 10:24:01 INFO zookeeper.ClientCnxn: Opening socket connection to server idx046.njcc.com/19
2.168.30.46:2181. Will not attempt to authenticate using SASL (unknown error)18/10/30 10:24:01 INFO zookeeper.ClientCnxn: Socket connection established to idx046.njcc.com/192.1
68.30.46:2181, initiating session18/10/30 10:24:01 INFO zookeeper.ClientCnxn: Session establishment complete on server idx046.njcc.c
om/192.168.30.46:2181, sessionid = 0x166bfdd54bf0006, negotiated timeout = 9000018/10/30 10:24:02 INFO zookeeper.ReadOnlyZKClient: Close zookeeper connection 0x36ebc363 to idx046:
2181java.io.IOException: java.lang.reflect.InvocationTargetException
at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java
:221) at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java
:87) at lsq.HelloHBase.Chapter4.init(Chapter4.java:32)
at lsq.HelloHBase.Chapter4.createTable(Chapter4.java:51)
at lsq.HelloHBase.Chapter4.main(Chapter4.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java
:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorI
mpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java
:219) ... 10 more
Caused by: java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/protobuf/generated/Authenticatio
nProtos$TokenIdentifier$Kind at org.apache.hadoop.hbase.ipc.AbstractRpcClient.
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.apache.hadoop.hbase.util.ReflectionUtils.instantiateWithCustomCtor(ReflectionUtils.j
ava:43) at org.apache.hadoop.hbase.ipc.RpcClientFactory.createClient(RpcClientFactory.java:88)
at org.apache.hadoop.hbase.ipc.RpcClientFactory.createClient(RpcClientFactory.java:64)
at org.apache.hadoop.hbase.client.ConnectionImplementation.
java:289) ... 15 more
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hbase.protobuf.generated.Authenticat
ionProtos$TokenIdentifier$Kind at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 22 more
Exception in thread "main" java.lang.NullPointerException
at lsq.HelloHBase.Chapter4.createTable(Chapter4.java:53)
at lsq.HelloHBase.Chapter4.main(Chapter4.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
18/10/30 10:24:02 INFO zookeeper.ZooKeeper: Session: 0x166bfdd54bf0006 closed
18/10/30 10:24:02 INFO zookeeper.ClientCnxn: EventThread shut down
[lsq@idx046 ~/data]$
错误: Caused by: java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/protobuf/generated/Authenticatio
nProtos$TokenIdentifier$Kind ??
org.apache.hadoop:hadoop-annotations:jar:2.7.4 : no hbase ?
org.apache.hadoop:hadoop-auth:jar:2.7.4 : no
org.apache.hadoop:hadoop-common:jar:2.7.4 : no
org.apache.hbase:hbase-hadoop2-compat:jar:2.1.0: no protobuf ?
org.apache.hbase:hbase-hadoop-compat:jar:2.1.0
编辑 pom.xml 添加依赖包:
org.apache.hbase:hbase-protocol:jar:2.1.0
OK!
*/
/*
Exception in thread "main" org.apache.hadoop.hbase.DoNotRetryIOException: java.lang.NoClassDefFound
Error: com/codahale/metrics/Metric at org.apache.hadoop.hbase.client.RpcRetryingCallerImpl.translateException(RpcRetryingCalle
rImpl.java:220) at org.apache.hadoop.hbase.client.RpcRetryingCallerImpl.callWithRetries(RpcRetryingCallerIm
pl.java:119) at org.apache.hadoop.hbase.client.HTable.get(HTable.java:386)
at org.apache.hadoop.hbase.client.HTable.get(HTable.java:360)
at org.apache.hadoop.hbase.MetaTableAccessor.getTableState(MetaTableAccessor.java:1078)
at org.apache.hadoop.hbase.MetaTableAccessor.tableExists(MetaTableAccessor.java:403)
at org.apache.hadoop.hbase.client.HBaseAdmin$6.rpcCall(HBaseAdmin.java:445)
at org.apache.hadoop.hbase.client.HBaseAdmin$6.rpcCall(HBaseAdmin.java:442)
at org.apache.hadoop.hbase.client.RpcRetryingCallable.call(RpcRetryingCallable.java:58)
at org.apache.hadoop.hbase.client.RpcRetryingCallerImpl.callWithRetries(RpcRetryingCallerIm
pl.java:107) at org.apache.hadoop.hbase.client.HBaseAdmin.executeCallable(HBaseAdmin.java:3084)
at org.apache.hadoop.hbase.client.HBaseAdmin.executeCallable(HBaseAdmin.java:3076)
at org.apache.hadoop.hbase.client.HBaseAdmin.tableExists(HBaseAdmin.java:442)
at lsq.HelloHBase.Chapter4.createTable(Chapter4.java:53)
at lsq.HelloHBase.Chapter4.main(Chapter4.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
Caused by: java.lang.NoClassDefFoundError: com/codahale/metrics/Metric
at org.apache.hadoop.hbase.ipc.AbstractRpcClient.callMethod(AbstractRpcClient.java:402)
at org.apache.hadoop.hbase.ipc.AbstractRpcClient.callBlockingMethod(AbstractRpcClient.java:
328) at org.apache.hadoop.hbase.ipc.AbstractRpcClient.access$200(AbstractRpcClient.java:95)
at org.apache.hadoop.hbase.ipc.AbstractRpcClient$BlockingRpcChannelImplementation.callBlock
ingMethod(AbstractRpcClient.java:571)
at org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos$ClientService$BlockingStu
b.get(ClientProtos.java:42510)
at org.apache.hadoop.hbase.client.ClientServiceCallable.doGet(ClientServiceCallable.java:50)
at org.apache.hadoop.hbase.client.HTable$1.rpcCall(HTable.java:381)
at org.apache.hadoop.hbase.client.HTable$1.rpcCall(HTable.java:376)
at org.apache.hadoop.hbase.client.RegionServerCallable.call(RegionServerCallable.java:127)
at org.apache.hadoop.hbase.client.RpcRetryingCallerImpl.callWithRetries(RpcRetryingCallerIm
pl.java:107) ... 19 more
Caused by: java.lang.ClassNotFoundException: com.codahale.metrics.Metric
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 29 more
[lsq@idx046 ~/data]$
错误:Caused by: java.lang.NoClassDefFoundError: com/codahale/metrics/Metric ??
添加依赖包: io.dropwizard.metrics:metrics-core:jar:3.2.1
OK!
*/
/*
18/10/30 11:00:35 INFO zookeeper.ZooKeeper: Initiating client connection, connectString=idx046:2181
sessionTimeout=90000 watcher=org.apache.hadoop.hbase.zookeeper.ReadOnlyZKClient$$Lambda$12/259950055@4c285d81
18/10/30 11:00:35 INFO zookeeper.ClientCnxn: Opening socket connection to server idx046.njcc.com/192.168.30.46:2181.
Will not attempt to authenticate using SASL (unknown error)
18/10/30 11:00:35 INFO zookeeper.ClientCnxn: Socket connection established to idx046.njcc.com/192.168.30.46:2181, initiating session
18/10/30 11:00:35 INFO zookeeper.ClientCnxn: Session establishment complete on server idx046.njcc.com/192.168.30.46:2181,
sessionid = 0x166bfdd54bf0009, negotiated timeout = 90000
18/10/30 11:00:40 INFO client.HBaseAdmin: Operation: CREATE, Table Name: default:student, procId: 5completed
18/10/30 11:00:40 INFO client.ConnectionImplementation: Closing master protocol: MasterService
18/10/30 11:00:40 INFO zookeeper.ReadOnlyZKClient: Close zookeeper connection 0x6a6cb05c to idx046:2181
18/10/30 11:00:40 INFO zookeeper.ZooKeeper: Session: 0x166bfdd54bf0009 closed
18/10/30 11:00:40 INFO zookeeper.ClientCnxn: EventThread shut down
18/10/30 11:00:40 INFO zookeeper.ReadOnlyZKClient: Connect 0x3a393455 to idx046:2181
with session timeout=90000ms, retries 30, retry interval 1000ms, keepAlive=60000ms
18/10/30 11:00:40 INFO zookeeper.ZooKeeper: Initiating client connection, connectString=idx046:2181
sessionTimeout=90000 watcher=org.apache.hadoop.hbase.zookeeper.ReadOnlyZKClient$$Lambda$12/259950055@4c285d81
18/10/30 11:00:40 INFO zookeeper.ClientCnxn: Opening socket connection to server idx046.njcc.com/192.168.30.46:2181.
Will not attempt to authenticate using SASL (unknown error)
18/10/30 11:00:40 INFO zookeeper.ClientCnxn: Socket connection established to idx046.njcc.com/192.168.30.46:2181, initiating session
18/10/30 11:00:40 INFO zookeeper.ClientCnxn: Session establishment complete on server idx046.njcc.com/192.168.30.46:2181,
sessionid = 0x166bfdd54bf000a, negotiated timeout = 90000
18/10/30 11:00:40 INFO zookeeper.ReadOnlyZKClient: Close zookeeper connection 0x3a393455 to idx046:2181
18/10/30 11:00:40 INFO zookeeper.ZooKeeper: Session: 0x166bfdd54bf000a closed
18/10/30 11:00:40 INFO zookeeper.ClientCnxn: EventThread shut down
18/10/30 11:00:40 INFO zookeeper.ReadOnlyZKClient: Connect 0x19553973 to idx046:2181 with session t
imeout=90000ms, retries 30, retry interval 1000ms, keepAlive=60000ms
18/10/30 11:00:40 INFO zookeeper.ZooKeeper: Initiating client connection, connectString=idx046:2181
sessionTimeout=90000 watcher=org.apache.hadoop.hbase.zookeeper.ReadOnlyZKClient$$Lambda$12/259950055@4c285d81
18/10/30 11:00:40 INFO zookeeper.ClientCnxn: Opening socket connection to server idx046.njcc.com/192.168.30.46:2181. Will not attempt to authenticate using SASL (unknown error)
18/10/30 11:00:40 INFO zookeeper.ClientCnxn: Socket connection established to idx046.njcc.com/192.168.30.46:2181, initiating session
18/10/30 11:00:40 INFO zookeeper.ClientCnxn: Session establishment complete on server idx046.njcc.com/192.168.30.46:2181, sessionid = 0x166bfdd54bf000b, negotiated timeout = 90000
18/10/30 11:00:40 INFO zookeeper.ReadOnlyZKClient: Close zookeeper connection 0x19553973 to idx046:2181
18/10/30 11:00:40 INFO zookeeper.ZooKeeper: Session: 0x166bfdd54bf000b closed
18/10/30 11:00:40 INFO zookeeper.ClientCnxn: EventThread shut down
18/10/30 11:00:40 INFO zookeeper.ReadOnlyZKClient: Connect 0x312ab28e to idx046:2181 with session timeout=90000ms,
retries 30, retry interval 1000ms, keepAlive=60000ms
18/10/30 11:00:40 INFO zookeeper.ZooKeeper: Initiating client connection, connectString=idx046:2181
sessionTimeout=90000 watcher=org.apache.hadoop.hbase.zookeeper.ReadOnlyZKClient$$Lambda$12/259950055@4c285d81
18/10/30 11:00:40 INFO zookeeper.ClientCnxn: Opening socket connection to server idx046.njcc.com/192.168.30.46:2181.
Will not attempt to authenticate using SASL (unknown error)
18/10/30 11:00:40 INFO zookeeper.ClientCnxn: Socket connection established to idx046.njcc.com/192.168.30.46:2181, initiating session
18/10/30 11:00:40 INFO zookeeper.ClientCnxn: Session establishment complete on server idx046.njcc.com/192.168.30.46:2181,
sessionid = 0x166bfdd54bf000c, negotiated timeout = 90000
18/10/30 11:00:40 INFO zookeeper.ReadOnlyZKClient: Close zookeeper connection 0x312ab28e to idx046:2181
18/10/30 11:00:40 INFO zookeeper.ZooKeeper: Session: 0x166bfdd54bf000c closed
18/10/30 11:00:40 INFO zookeeper.ClientCnxn: EventThread shut down
18/10/30 11:00:40 INFO zookeeper.ReadOnlyZKClient: Connect 0x03e10dc6 to idx046:2181 with session timeout=90000ms,
retries 30, retry interval 1000ms, keepAlive=60000ms
18/10/30 11:00:40 INFO zookeeper.ZooKeeper: Initiating client connection, connectString=idx046:2181
sessionTimeout=90000 watcher=org.apache.hadoop.hbase.zookeeper.ReadOnlyZKClient$$Lambda$12/259950055@4c285d81
18/10/30 11:00:40 INFO zookeeper.ClientCnxn: Opening socket connection to server idx046.njcc.com/192.168.30.46:2181.
Will not attempt to authenticate using SASL (unknown error)
18/10/30 11:00:40 INFO zookeeper.ClientCnxn: Socket connection established to idx046.njcc.com/192.168.30.46:2181, initiating session
18/10/30 11:00:40 INFO zookeeper.ClientCnxn: Session establishment complete on server idx046.njcc.com/192.168.30.46:2181,
sessionid = 0x166bfdd54bf000d, negotiated timeout = 90000
69 ---这里!是输出!
18/10/30 11:00:40 INFO zookeeper.ReadOnlyZKClient: Close zookeeper connection 0x03e10dc6 to idx046:2181
18/10/30 11:00:40 INFO zookeeper.ZooKeeper: Session: 0x166bfdd54bf000d closed
18/10/30 11:00:40 INFO zookeeper.ClientCnxn: EventThread shut down
[lsq@idx046 ~/data]$
正常结束了,没有输出?
shell查看:
hbase(main):001:0> list
TABLE
member
student
2 row(s)
Took 2.0126 seconds
=> ["member", "student"]
表创建成功!
hbase(main):005:0> descipter student
NameError: undefined local variable or method `student' for main:Object
hbase(main):006:0> scan 'student'
ROW COLUMN+CELL
Jack column=score:Computer, timestamp=1540868440851, value=77
Jack column=score:English, timestamp=1540868440711, value=69
Jack column=score:Math, timestamp=1540868440781, value=86
1 row(s)
Took 0.8493 seconds
表插入成功!
hbase(main):008:0> get 'student','Jack',{COLUMN=>'score:English'}
COLUMN CELL
score:English timestamp=1540868440711, value=69
1 row(s)
Took 0.0106 seconds
读取正确!
疑问: 程序的输出语句怎么看不到输出信息?
增加输出语句:
String msg = new String(result.getValue(colFamily.getBytes(),col==null?null:col.getBytes()));
System.out.println(msg);
Log.info(msg ); -- 新增!
*/
/*
18/10/30 11:24:52 INFO zookeeper.ClientCnxn: Session establishment complete on server idx046.njcc.com/192.168.30.46:2181, sessionid = 0x166bfdd54bf0014, negotiated t
imeout = 90000
69 --啊,这里是输出!
18/10/30 11:24:52 INFO mortbay.log: Logging to org.slf4j.impl.Log4jLoggerAdapter(org.mortbay.log) via org.mortbay.log.Slf4jLog
18/10/30 11:24:52 INFO mortbay.log: 69 -- 新增!
18/10/30 11:24:52 INFO zookeeper.ReadOnlyZKClient: Close zookeeper connection 0x101639ae to idx046:2181
18/10/30 11:24:52 INFO zookeeper.ZooKeeper: Session: 0x166bfdd54bf0014 closed
18/10/30 11:24:52 INFO zookeeper.ClientCnxn: EventThread shut down
*/