0

I'm trying to compile and run my simple test HBase code in java using terminal Ubuntu 14.04, I've install Hadoop and HBase correctlly and are running. The code is :

/*
 * 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();
        }
    }
}

I've got the long string 'hbase classpath' and the command

javac -cp 'hbase classpath' TestHBase.java

run correctly giving TestHBase.class file, but when I run the command

java -cp 'hbase classpath' TestHBase

it gives this error :

Error: Could not find or load main class

How could I solve this ?

Here is my terminal screenshot 1 2

  • Can you please give the full path to your TestHBase. I think the .class is in a different folder something like java -cp 'hbase classpath' c:\temp\TestHBase – user3509208 Feb 19 '16 at 17:12
  • my TestHBase.java file is in /home (i'm using ubuntu) , and after command `javac -cp 'hbase classpath' TestHBase.java` I see TestHBase.class creating in /home, but when I issue command `java -cp 'hbase classpath' TestHBase`, it gives error. In addition I try a simple "hello world" java code using terminal and it works correctly. –  Feb 19 '16 at 17:33
  • Can you please post a screen shot of your command prompt – user3509208 Feb 19 '16 at 18:20
  • Yes, for sure. I added two screenshot in the end of the main post. The first is when I issue `javac -cp 'hbase classpath' TestHBase.java` and the second is when I issue `java -cp 'hbase classpath' TestHBase`. you can see TestHBase.java file in /home directory. Thanks –  Feb 20 '16 at 08:06
  • i had a look at your screenshot but not sure what is amiss. Hopefully the below link provides you some answers http://stackoverflow.com/questions/18093928/what-does-could-not-find-or-load-main-class-mean – user3509208 Feb 24 '16 at 04:04

0 Answers0