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

╄→尐↘猪︶ㄣ 提交于 2019-12-01 10:55:50

问题


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?


回答1:


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.




回答2:


I have faced same problem when using earlier versions of jars for hadoop-core and hadoop-auth. Using below version jars resolves my problem.

hadoop-core-1.2.1.jar

hadoop-auth-2.2.0.jar




回答3:


I had such problem, and removed the fs (filesystem) and security from the hadoop-common-X.X.X.jar. Then I added its compatible source code to my java source codes. Besides I removed hadoop-auth. because it was my first test, I removed them to get my code running.



来源:https://stackoverflow.com/questions/24105852/java-lang-nosuchfielderror-ibm-java-for-a-simple-hbase-java-client-in-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!