2010-02-01 5 views
3
import java.io.IOException; 

import org.apache.hadoop.hbase.HBaseConfiguration; 
import org.apache.hadoop.hbase.client.Get; 
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 HBaseExample { 
    public static void main(String[] args) throws IOException { 

    HBaseConfiguration config = new HBaseConfiguration(); 

    HTable table = new HTable(config, "myLittleHBaseTable"); 



    Put p = new Put(Bytes.toBytes("myLittleRow")); 

    p.add(Bytes.toBytes("myLittleFamily"), Bytes.toBytes("someQualifier"), 
     Bytes.toBytes("Some Value")); 


    table.put(p); 

    Get g = new Get(Bytes.toBytes("myLittleRow")); 
    Result r = table.get(g); 
    byte [] value = r.getValue(Bytes.toBytes("myLittleFamily"), 
     Bytes.toBytes("someQualifier")); 

    String valueStr = Bytes.toString(value); 
    System.out.println("GET: " + valueStr); 

    Scan s = new Scan(); 
    s.addColumn(Bytes.toBytes("myLittleFamily"), Bytes.toBytes("someQualifier")); 
    ResultScanner scanner = table.getScanner(s); 
    try { 
ult instances. 
     // Now, for the actual iteration. One way is to use a while loop like so: 
     for (Result rr = scanner.next(); rr != null; rr = scanner.next()) { 
     // print out the row we found and the columns we were looking for 
     System.out.println("Found row: " + rr); 
     } 


    } finally { 
clause 
     scanner.close(); 
    } 
    } 
} 

Caused by: java.lang.ClassNotFoundException: HBaseExample 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:252) 
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) 
Could not find the main class: HBaseExample. Program will exit. 
+0

un code, peut-être? Il peut aider, je doute qu'il y ait des gens avec la capacité de voir l'écran que vous regardez sans être à côté de vous – ant

Répondre

2

Comment faites-vous ce test? Vous devez vous assurer que les fichiers Hadoop et HBase sont dans votre classpath lors de son exécution. Je vous recommande de l'exécuter dans le contexte de Hadoop, par exemple

/usr/local/hadoop/bin/hadoop jar YourJar.jar 

Les chances sont votre problème est lié classpath-chose.