I am facing issue with run simple Hbase example.
I have create on HbaseTest.java which create one table and insert some records. In Unix, I can able to compile the java class. by.
$javac -classpath hbase-0.94.2.jar:hadoop-core-1.0.4.jar HBaseTest.java
But I am not able to run this program by : $java -classpath hbase-0.94.2.jar:hadoop-core-1.0.4.jar HBaseTest
Above command is not working for me. Not sure what is the issue ? Is it correct way to run Hbase Java Example ?
You can use "hbase classpath" to get the class path needed.
/*
* Compile and run with:
* javac -cp `hbase classpath` TestHBase.java
* java -cp `hbase classpath` TestHBase
*/
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.*;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.*;
public class TestHBase {
public static void main(String[] args) throws Exception {
Configuration conf = HBaseConfiguration.create();
HBaseAdmin admin = new HBaseAdmin(conf);
try {
HTable table = new HTable(conf, "test-table");
Put put = new Put(Bytes.toBytes("test-key"));
put.add(Bytes.toBytes("cf"), Bytes.toBytes("q"), Bytes.toBytes("value"));
table.put(put);
} finally {
admin.close();
}
}
}
If it fails to run you could, if possible, use an IDE like NetBeans to develop Java HBase Client API programs.
/usr/local/hadoop-2.x.x/share/hadoop for hadoop libraries and/usr/local/hbase-1.x.x/lib for HBase libraries, by navigating the file system browser(or just navigate to your installation directories). Shift+arrow keys work to mass select jar files.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With