如何使用Eclipse构建HBase开发环境
来源:互联网 发布:独立软件供应商 编辑:程序博客网 时间:2024/05/21 22:30
环境需求
Eclipse版本:eclipse-jee-mars-1
操作系统:Ubuntu15.04
Hadoop:1.2.1
HBase:0.94.13搭建过程
运行Eclipse,创建一个新的Java工程“hbaseTest”,右键项目根目录,选择 “Properties”->“Java Build Path”->“Library”->“Add External JARs”,将HBase解压后根目录下的hbase-0.94.13-security.jar、hbase-0.94.13-security-tests.jar和lib子目录下所有jar 包添加到本工程的Classpath下。
工程根目录下创建文件夹conf,将hbase解压后根目录下的conf文件夹内的hbase-site.xml拷贝过来。测试
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.client.HBaseAdmin;import org.apache.hadoop.hbase.client.HTable;import org.apache.hadoop.hbase.client.Put;import org.apache.hadoop.hbase.util.Bytes;public class putExample { public static void main(String[] args) throws IOException { Configuration conf = HBaseConfiguration.create(); HTable table =new HTable(conf, "testtable1"); Put put = new Put(Bytes.toBytes("row1")); put.add(Bytes.toBytes("colfam1"),Bytes.toBytes("qual1"),Bytes.toBytes("val1")); put.add(Bytes.toBytes("colfam1"),Bytes.toBytes("qual2"),Bytes.toBytes("val2")); table.put(put); }}
会出现如下错误:
WARN client.HConnectionManager$HConnectionImplementation: Encountered problems when prefetch META table:
org.apache.hadoop.hbase.TableNotFoundException: Cannot find row in .META. for table: testtable1, row=testtable1,,99999999999999
是因为没有创建表结构,所以代码应改为
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.client.HBaseAdmin;import org.apache.hadoop.hbase.client.HTable;import org.apache.hadoop.hbase.client.Put;import org.apache.hadoop.hbase.util.Bytes;public class putExample { public static void main(String[] args) throws IOException { Configuration conf = HBaseConfiguration.create(); HBaseAdmin hbase=new HBaseAdmin(conf); HTableDescriptor desc=new HTableDescriptor("testtable"); HColumnDescriptor colfam1=new HColumnDescriptor("colfam1".getBytes()); desc.addFamily(colfam1); hbase.createTable(desc); HTable table =new HTable(conf, "testtable"); Put put = new Put(Bytes.toBytes("row1")); put.add(Bytes.toBytes("colfam1"),Bytes.toBytes("qual1"),Bytes.toBytes("val1")); put.add(Bytes.toBytes("colfam1"),Bytes.toBytes("qual2"),Bytes.toBytes("val2")); table.put(put); }}
0 0
- 如何使用Eclipse构建HBase开发环境
- Hbase学习全程记录——使用Eclipse构建HBase开发环境
- 如何在 Eclipse 中使用插件构建 PHP 开发环境
- HBase总结(十四)LINUX下用Eclipse构建HBase开发环境
- HBase总结(十四)LINUX下用Eclipse构建HBase开发环境
- eclipse构建HBase开发环境并运行实例对Hbase建表增删改查
- HBase总结(十四)LINUX下用Eclipse构建HBase开发环境
- 如何使用HBase构建NewSQL?
- 【HBase】HBase的eclipse开发环境搭建
- hbase+eclipse开发环境配置
- 如何在eclipse中构建scala开发环境
- Linux下用Eclipse构建HBase开发环境 (总结13)
- 使用Eclipse IDE for CC++ Developers 构建C++开发环境
- 使用eclipse构建现有的maven项目开发环境
- 使用Eclipse构建Spark Java集成开发环境
- 使用Eclipse开发HBase应用程序
- 使用Eclipse开发HBase应用程序
- HBase 开发环境搭建(Eclipse+Maven)
- 让你的MyEclipse自动提示jquery和extjs等
- struts2 ajax
- PowerDesigner反向工程,根据数据库结构生成ER图(Oracle)
- BCM芯片介绍
- 项目小记
- 如何使用Eclipse构建HBase开发环境
- bos webservice开发流程
- java里程碑之泛型--擦除和转换
- jQuery事件之鼠标事件
- android 实现listView的A-Z字幕排序
- android事件机制个人理解
- VC小技巧二:变量初始化
- github建立本地与远程仓库的连接
- CSS层叠样式表