which class is not in classpath ??? I already put hadoop-core.jar , hbase-core.jar and zookeeper.jar in my classpaths... What else I need to put in my classpath ???
On Tue, May 24, 2011 at 3:48 PM, Vivek Mishra <[email protected]>wrote: > It means Class is not in your classpath. > > -----Original Message----- > From: praveenesh kumar [mailto:[email protected]] > Sent: Tuesday, May 24, 2011 3:31 PM > To: [email protected] > Subject: How to compile simple Hbase code ? > > I am simply using HBase API, not doing any Map-reduce work on it. > Following is the code I have written , simply creating the file on HBase: > > import java.io.IOException; > 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 ExampleClient { > public static void main(String args []) throws IOException { > HBaseConfiguration config = new HBaseConfiguration(); > > HBaseAdmin admin = new HBaseAdmin(config); > HTableDescriptor htd = new HTableDescriptor("test"); > HColumnDescriptor hcd = new HColumnDescriptor("data"); > htd.addFamily(hcd); > admin.createTable(htd); > > byte [] tablename = htd.getName(); > HTableDescriptor [] tables = admin.listTables(); > > if(tables.length !=1 && Bytes.equals(tablename, tables[0].getName())) > { > throw new IOException("Failed to create table"); > } > > HTable table = new HTable(config,tablename); > byte[] row1 = Bytes.toBytes("row1"); > Put p1 = new Put(row1); > byte[] databytes = Bytes.toBytes("data"); > p1.add(databytes,Bytes.toBytes("1"),Bytes.toBytes("value1")); > table.put(p1); > > Get g = new Get(row1); > Result result = table.get(g); > System.out.println("Get : "+ result); > Scan scan = new Scan(); > ResultScanner scanner = table.getScanner(scan); > try > { > for(Result scannerResult: scanner) > { > System.out.println("Scan : " + scannerResult); > } > }catch(Exception e ){ > e.printStackTrace(); > } > finally{ > scanner.close(); > } > table.close(); > } > } > > Now I have set the classpath variable in /etc/environment as > > * > > MYCLASSPATH="/usr/local/hadoop/hadoop/hadoop-0.20.2-core.jar:/usr/local/hadoop/hbase/hbase/hbase-0.20.6.jar:/usr/local/hadoop/hbase/hbase/lib/zookeeper-3.2.2.jar > * > now I am compiling my code with javac command > > *$javac -classpath $MYCLASSPATH ExampleClient.java > * > It is working fine. > While running, I am using java command > *$java -classpath $MYCLASSPATH ExampleClient*, > > then I am getting the following error : > *Exception in thread "main" java.lang.NoClassDefFoundError: ExampleClient > Caused by: java.lang.ClassNotFoundException: ExampleClient* > > * at java.net.URLClassLoader$1.run(URLClassLoader.java:217) > at java.security.AccessController.doPrivileged(Native Method) > at java.net.URLClassLoader.findClass(URLClassLoader.java:205) > at java.lang.ClassLoader.loadClass(ClassLoader.java:321) > at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294) > at java.lang.ClassLoader.loadClass(ClassLoader.java:266)* > > Could not find the main class: ExampleClient. Program will exit. > > But I am running the code from the same location. and ExampleClient.class > file exists at that location. > > ________________________________ > > Write to us for a Free Gold Pass to the Cloud Computing Expo, NYC to attend > a live session by Head of Impetus Labs on ‘Secrets of Building a Cloud > Vendor Agnostic PetaByte Scale Real-time Secure Web Application on the Cloud > ‘. > > Looking to leverage the Cloud for your Big Data Strategy ? Attend Impetus > webinar on May 27 by registering at > http://www.impetus.com/webinar?eventid=42 . > > > NOTE: This message may contain information that is confidential, > proprietary, privileged or otherwise protected by law. The message is > intended solely for the named addressee. If received in error, please > destroy and notify the sender. Any use of this email is prohibited when > received in error. Impetus does not represent, warrant and/or guarantee, > that the integrity of this communication has been maintained nor that the > communication is free of errors, virus, interception or interference. >
