Reply
New Contributor
Posts: 3
Registered: ‎02-17-2016

java.lang.noClassDefFoundError: org/apache/hadoop/util/PlatformName in Hbase java program

Hi,

I wrote a java program to create a HBASE table in Eclipse Luna on CDH VM (Virtual Box) on my laptop. The Error is as follows:

Exception in thread "main" java.lang.noClassDefFoundError: org/apache/hadoop/util/PlatformName

at org.apache.hadoop.security.UserGroupInformation.getOSLoginModuleName(userGroupInformation.java:365)

at org.apache.hadoop.security.UserGroupInformation.<clinit>(userGroupInformation.java:410)

at org.apache.hadoop.hbase.security.User$SecureHadoopUser.<init>(User.java:283)

at org.apache.hadoop.hbase.security.User$SecureHadoopUser.<init>(User.java:279)

at org.apache.hadoop.hbase.security.User.getCurrent(UserProvider.java:88)

at org.apache.hadoop.hbase.client.HConnectionkey.<init>(HConnection.java:72)

at org.apache.hadoop.hbase.client.ConnectionManager.getConnectionInternal(ConnectionManager.java:281)

at org.apache.hadoop.hbase.client.HBaseAdmin.<init>(HBaseAdmin.java:207)

at CrHbase.main(CrHbase.java:19)

caused by java.lang.ClassNotFoundException: org.apache.hadoop.util.PlatformName

at java.net.URLClassLoader$1.run(URLClassLoader.java:366)

at java.net.URLClassLoader$1.run(URLClassLoader.java:355)

..10 more

 

The Code is

import java.io.Exception;

import java.apache.hadoop.conf.Configuration;

import java.apache.hadoop.hbase.HBaseConfiguration;

import java.apache.hadoop.hbase.HColumnDescriptor;

import java.apache.hadoop.hbase.HTableDescriptor;

import java.apache.hadoop.hbase.client.HBaseAdmin;

 

public class CrHbase

{

@SuppressWarnings("deprecation"

 

public static void main(String[] args) throws IOException

{

HBaseConfiguration hConfig = new HBaseConfiguration(new Configuration());

HTableDescriptor htable = new HTableDescriptor("User");

htable.addFamily(new HColumnDescriptor("Id'"));

htable.addFamily(new HColumnDescriptor("Name"));

HBaseAdmin hadmin = new HBaseAdmin(hConfig);

hadmin.createTable(htable);

hadmin.close(); 

}

}

 

Please note that the words marked in red were marked as striked thru by Eclipse.

 

Can you please assist in this? Need to fix this. Also, I am not sure f I am posting it to in the correct group. Please move this post if this is the wrong group

Posts: 1,892
Kudos: 432
Solutions: 302
Registered: ‎07-31-2013

Re: java.lang.noClassDefFoundError: org/apache/hadoop/util/PlatformName in Hbase java program

How are you supplying your dependencies? I'd recommend using Maven in Eclipse to not face these trivial problems that arise out of manually managing jars and dependencies. You can read and adapt this blog post: http://blog.cloudera.com/blog/2012/08/developing-cdh-applications-with-maven-and-eclipse/
Posts: 1,892
Kudos: 432
Solutions: 302
Registered: ‎07-31-2013

Re: java.lang.noClassDefFoundError: org/apache/hadoop/util/PlatformName in Hbase java program

The strikethroughs are related to API deprecations. You can read more on this over the API docs for each class shown: http://archive.cloudera.com/cdh5/cdh/5/hbase/apidocs/
New Contributor
Posts: 3
Registered: ‎02-17-2016

Re: java.lang.noClassDefFoundError: org/apache/hadoop/util/PlatformName in Hbase java program

Thank you for a quick reply. Let me check these links that you shared.
Highlighted
New Contributor
Posts: 3
Registered: ‎02-17-2016

Re: java.lang.noClassDefFoundError: org/apache/hadoop/util/PlatformName in Hbase java program

I created a maven project in CDH Eclipse Luna and tried to run a Hbase program to read from Hbase table. I submitted the job as 'Run as Java Application'. But, it gave an error as :

 

 

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/HBaseConfiguration
    at GrpHb.ArtHb.App.<clinit>(App.java:21)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hbase.HBaseConfiguration
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 1 more

 

The code is :

package GrpHb.ArtHb;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
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.client.Table;

/**
 * Hello world!
 *
 */
public class App
{
    static Configuration conf = HBaseConfiguration.create();
    public static void main( String[] args ) throws IOException
    {
        System.out.println( "Hello World!" );
        conf.set("hbase.zookeeper.quorum", "quickstart.cloudera");
        conf.set("hbase.zookeeper.property.clientPort", "2181");
        
        Connection connection = ConnectionFactory.createConnection(conf);
        Table table = connection.getTable(TableName.valueOf("class"));
        
        Scan scan1 = new Scan();
        ResultScanner scanner1 = table.getScanner(scan1);
     
        for (Result res : scanner1)
        {
            System.out.println(res);
        }
    }
}

 

and the pom.xml is

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>GrpHb</groupId>
  <artifactId>ArtHb</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>ArtHb</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.apache.hbase</groupId>
      <artifactId>hbase-client</artifactId>
      <version>1.0.0</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.hbase</groupId>
      <artifactId>hbase-common</artifactId>
      <version>1.0.0</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

Announcements