java.lang.NoSuchFieldError: IBM_JAVA for a simple hbase java client in Eclipse

wuchang picture wuchang · Jun 8, 2014 · Viewed 8.2k times · Source

As the title goes.My source code is:

package hbase;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.util.Bytes;

public class HbaseExampleClient {
public static void main(String[] args) throws IOException {
    Configuration config = HBaseConfiguration.create();
    config.set("hbase.zookeeper.quorum", "192.168.10.17");
    config.set("hbase.zookeeper.property.clientPort", "2222");
    HBaseAdmin admin = new HBaseAdmin(config);//reports an IBM_JAVA NoSuchFieldError
    HTableDescriptor htd = new HTableDescriptor("test1111");
    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 create of table!");
    }
    admin.close();
}
}

Exception in thread "main" java.lang.NoSuchFieldError: IBM_JAVA
    at org.apache.hadoop.security.UserGroupInformation.getOSLoginModuleName(UserGroupInformation.java:337)
    at org.apache.hadoop.security.UserGroupInformation.<clinit>(UserGroupInformation.java:382)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.hadoop.hbase.util.Methods.call(Methods.java:37)
    at org.apache.hadoop.hbase.security.User.call(User.java:624)
    at org.apache.hadoop.hbase.security.User.callStatic(User.java:614)
    at org.apache.hadoop.hbase.security.User.access$300(User.java:52)
    at org.apache.hadoop.hbase.security.User$SecureHadoopUser.<init>(User.java:431)
    at org.apache.hadoop.hbase.security.User$SecureHadoopUser.<init>(User.java:426)
    at org.apache.hadoop.hbase.security.User.getCurrent(User.java:177)
    at org.apache.hadoop.hbase.client.UserProvider.getCurrent(UserProvider.java:78)
    at org.apache.hadoop.hbase.client.UserProvider.getCurrentUserName(UserProvider.java:62)
    at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionKey.<init>(HConnectionManager.java:473)
    at org.apache.hadoop.hbase.client.HConnectionManager.getConnection(HConnectionManager.java:198)
    at org.apache.hadoop.hbase.client.HBaseAdmin.<init>(HBaseAdmin.java:116)
    at hbase.HbaseExampleClient.main(HbaseExampleClient.java:19)

It seems that this error has nothing to do with hbase server because I can use hbase shell properly. But I really don't konw how to fix this problem.Both from my Laptop(windows) Eclipse and a remote desktop(Ubuntu) linux Eclipse reports the same error.

Anyone can help me?

Answer

Alok Pathak picture Alok Pathak · Aug 13, 2014

I was also facing the same problem but found the solution, This problem occurs due to jar issue since IBM_JAVA is constant

 public static final boolean IBM_JAVA = JAVA_VENDOR_NAME.contains("IBM");

and this constant is define in class org.apache.hadoop.util.PlatformName but this package structure and class is define in two jars:

  1. hadoop-core
  2. hadoop-auth

but the class present in hadoop-core does not have this constant.

IBM_JAVA

And your application trying to search in hadoop-core jar. So add hadoop-auth jar in your application.