The Eclipse,hbase version is not currently found to be specifically specified.
1: Copy an hbase deployment file from the HBase cluster, placed in a directory on the development side (as in the/app/hadoop/hbase096 directory).
2: Create a new Java project in Eclipse HBase, then select the project Properties, Libraries->add External JARs ..., and then select the relevant jar package under/app/hadoop/hbase096/lib , if it's just a test, simply put all the jars in the selection.
3: Add a Folder conf under Project HBase, copy the HBase cluster's configuration file Hbase-site.xml to the directory, and then select the project properties at Libraries->add Class folder, Select the Conf directory that you just added.
4: Add a Chapter12 package to the HBase project, then add a hbasetestcase class and then copy the code from the Lu Jiaheng Teacher's "Hadoop Combat 2nd Edition" 12 to make the appropriate changes, as follows:
Package Chapter12;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.get;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.client.result;import Org.apache.hadoop.hbase.client.resultscanner;import Org.apache.hadoop.hbase.client.scan;import Org.apache.hadoop.hbase.util.bytes;public class HBaseTestCase {/ /declare static configuration hbaseconfiguration static config cfg=hbaseconfiguration.create (); Create a table with Hbaseadmin htabledescriptor to create public static void Creat (String tablename,string columnfamily) throws Exceptio n {hbaseadmin admin = new hbaseadmin (CFG); if (admin.tableexists (tablename)) {System.out.println ("table exists!"); System.exit (0); } else{Htabledescriptor Tabledesc = new Htabledescriptor (tablename); Tabledesc.addfamily (New Hcolumndescriptor (columnfamily)); Admin.createtable (TABLEDESC); SYSTEM.OUT.PRINTLN ("CREATE Table success!"); }}//Add a piece of data by Htable put to an existing table to add data public static void put (string tablename,string row, String columnfamily,s Tring column,string data) throws Exception {htable table = new htable (CFG, tablename); Put P1=new put (bytes.tobytes (row)); P1.add (Bytes.tobytes (columnfamily), bytes.tobytes (column), bytes.tobytes (data)); Table.put (p1); System.out.println ("Put" "+row+" ', ' "+columnfamily+": "+column+" ', ' "+data+" ' "); public static void Get (String tablename,string row) throws ioexception{htable table=new htable (cfg,tabl ENAME); Get G=new Get (bytes.tobytes (row)); Result Result=table.get (g); System.out.println ("GET: "+result); }//Show all data via htable scan to get information about existing tables public static void scan (String tablename) throws exception{htable table = New Htable (CFG, tablename); Scan s = new scan (); Resultscanner rs = Table.getscanner (s); for (Result r:rs) {System.out.println ("Scan:" +r); }} public static Boolean delete (String tablename) throws ioexception{Hbaseadmin Admin=n EW hbaseadmin (CFG); if (admin.tableexists (tablename)) {try {admin.disabletabl E (tablename); Admin.deletetable (tablename); }catch (Exception ex) {ex.printstacktrace (); return false; }} return true; public static void Main (string [] agrs) {string tablename= "HBASE_TB"; String columnfamily="CF"; try {hbasetestcase.creat (tablename, columnfamily); Hbasetestcase.put (tablename, "Row1", columnfamily, "CL1", "data"); Hbasetestcase.get (tablename, "Row1"); Hbasetestcase.scan (tablename); /* IF (True==hbasetestcase.delete (tablename)) System.out.println ("Delete table:" +tablename+ "su Ccess! "); */} catch (Exception e) {e.printstacktrace (); } }}
5: Set the Run configuration, and then run. Start the HBase cluster first before running.
6: Test, use hbase shell to view hbase and find that table HBASE_TB has been established.
During the period of self-encounter points:
1. Introduction of the jar package, two packets without Read permission, resulting in a red exclamation point item
2. Because I am a virtual machine, I want to restart Hadoop and hbase every time, so don't forget to set up Hadoop as non-secure mode
HBase Learning (14) building an hbase development environment with Eclipse under Linux