How can I run the code from the command line?
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 MyHBase { 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(); } } }
How to set the path to hbase classes? I get a huge string in my classpath.
UPDATE
root# vi MyHBase.java hbase-0.92.2 root# java -classpath `hbase classpath`:./ /var/root/MyHBase -sh: hbase: command not found Exception in thread "main" java.lang.NoClassDefFoundError: /var/root/MyHBase Caused by: java.lang.ClassNotFoundException: .var.root.MyHBase at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
I can do
hbase-0.92.2 root# bin/hbase shell HBase Shell; enter 'help<RETURN>' for list of supported commands. Type "exit<RETURN>" to leave the HBase Shell Version 0.92.2, r1379292, Fri Aug 31 13:13:53 UTC 2012 hbase(main):001:0> exit
Am I doing something wrong?
source share