HBase Forum

HBase Java Application

  • #12466
    David Choe
    Member

    I am trying to compile and run a HBase Java application with Ant on Amazon EC2 Sandbox.
    Is a tutorial available?

    Thanks
    David

to create new topics or reply. | New User Registration

  • Author
    Replies
  • #12468
    Seth Lyubich
    Moderator

    Hi David,

    Thank you for using HDP.

    I don’t think we have specific tutorial available. I will check further and will let you know if I find anything.

    Regards,
    Seth

    #12483
    David Choe
    Member

    I have more specific question.
    I can build an hbase app using ant build.xml, but I got run-time error. I think it is because path was not defined in my app.
    Can you explain how to integrate Hortonwork hbase-site.xml with Ant build.xml ?

    Regards,
    David

    #12484
    Sasha J
    Moderator

    David,
    could you please be more specific?
    What is your app configuration related code and what it your ant build.xml have in it?

    Thank you!
    Sasha

    #12485
    David Choe
    Member

    My hbase app is to write and read data to hbase in hortonworks.
    I added the following to my java code instead of build.xml
    config.addResource(new Path(“/etc/hadoop/conf/core-site.xml”));
    config.addResource(new Path(“/etc/hadoop/conf/hdfs-site.xml”));
    config.addResource(new Path(“/etc/hbase/conf/hbase-site.xml”));

    Still I have the following errors:

    [root@hortonworks-sandbox dist]# java -jar H*.jar
    Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/HBaseConfiguration
    at HBaseConnector.main(Unknown Source)
    Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hbase.HBaseConfiguration
    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)
    … 1 more

    #12486
    tedr
    Member

    Hi David,

    Are you running some tests after you build HBase? If not please explain why you need to integrate hbase-site.xml in an Ant script. If you are trying to run HBase after building it, after installing HBase there is usually a start script in the HBase install directory. Also one thing that is not apparent from your earlier posts, you do have hadoop up and running on the box where you tryim go run HBase right?

    Thanks,

    Ted.

    #12487
    David Choe
    Member

    I can run hbase shell to create a hbase table.
    You may be right. I don’t have to add hbase-site.xml to ant build.xml. Instead I added hbase-site.xml to my code as shown in the previous.

    Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hbase.HBaseConfiguration indicates that my app couldn’t find the class even though I defined CLASSPATH in .bash_profile such that

    CLASSPATH=/usr/lib/hbase/hbase-0.92.1.15.jar
    export CLASSPATH

    [root@hortonworks-sandbox dist]# echo $CLASSPATH
    /usr/lib/hbase/hbase-0.92.1.15.jar

    Any suggestions?

    #12488
    tedr
    Member

    Hi David,

    The exception could also mean that the jar didn’t get built correctly and the specific class is either missing or in an unexpected place within the jar file.

    Thanks,
    Ted.

    #12490
    tedr
    Member

    Hi David,

    Another thing, somewhere in the directory where hbase was built there should a script called hbase-start.sh, which should be used to start hbase. When launched with this script it will properly set the classpath. When you set the classpath as you did earlier, it will have only that jar on the classpath and there are MANY other jars that are needed for HBase to run.

    Thanks,
    Ted.

    #12491
    David Choe
    Member

    I ran the app with ant and get

    [java] GET: Some Value
    [java] Found row: keyvalues={myLittleRow/myLittleFamily:someQualifier/1354575201826/Put/vlen=10}

    BUILD SUCCESSFUL
    Total time: 5 seconds

    Does this indicate my app successfully accessed the hbase table?

    Regards,
    David

    #12492
    tedr
    Member

    Hi David,

    It is real difficult to tell what it means when you run it with ant, not knowing what the ant file contains. It could mean what you expect, or it could mean that it was just successfully compiled. I strongly suggest that you find the script I mentioned earlier and use that to launch it, as that is the only way you can be sure that all of the correct jars are on the classpath and the correct environment variables are set.

    Thanks,
    Ted.

You must be to reply to this topic. | Create Account

Support from the Experts

A HDP Support Subscription connects you experts with deep experience running Apache Hadoop in production, at-scale on the most demanding workloads.

Enterprise Support »

Become HDP Certified

Real world training designed by the core architects of Hadoop. Scenario-based training courses are available in-classroom or online from anywhere in the world

Training »

Hortonworks Data Platform
The Hortonworks Data Platform is a 100% open source distribution of Apache Hadoop that is truly enterprise grade having been built, tested and hardened with enterprise rigor.
Get started with Sandbox
Hortonworks Sandbox is a self-contained virtual machine with Apache Hadoop pre-configured alongside a set of hands-on, step-by-step Hadoop tutorials.
Modern Data Architecture
Tackle the challenges of big data. Hadoop integrates with existing EDW, RDBMS and MPP systems to deliver lower cost, higher capacity infrastructure.