java.lang.NoSuchFieldError:用于Eclipse中的简单hbase Java客户机的IBM_JAVA [英] java.lang.NoSuchFieldError: IBM_JAVA for a simple hbase java client in Eclipse

查看:321
本文介绍了java.lang.NoSuchFieldError:用于Eclipse中的简单hbase Java客户机的IBM_JAVA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的源代码是:

  package hbase; 

import java.io.IOException;

导入org.apache.hadoop.conf.Configuration;
导入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); //报告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();



线程main中的异常java.lang.NoSuchFieldError:IBM_JAVA
at org.apache.hadoop.security.UserGroupInformation.getOSLoginModuleName(UserGroupInformation。
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)
在org.apache.hadoop.hbase.security.User.callStatic(User.java:614)
在org.apache.hadoop.hbase.security.User.access $ 300(User.java:52)
在org.apache.hadoop.hbase.security.User $ SecureHadoopUser。< init>(User.java:431)
在org.apache.had oop.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)
在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)

似乎这个错误与hbase服务器无关,因为我可以正确使用hbase shell。
但是我真的不知道如何解决这个问题。从我的笔记本电脑(Windows)Eclipse和远程桌面(Ubuntu)的Linux Eclipse报告同样的错误。

任何人都可以帮助我?

解决方案

我也面临同样的问题,但发现解决方案
由于IBM_JAVA是常量,所以出现此问题。

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

这个常量是在类org.apache.hadoop.util.PlatformName中定义的,但是这个包结构和class是在两个jar中定义的:


  1. hadoop-core

  2. hadoop-auth

但hadoop-core中存在的类没有这个常量。


IBM_JAVA

而您的应用程序试图在hadoop-core jar中进行搜索。
因此,在您的应用程序中添加hadoop-auth jar。


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?

解决方案

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.

这篇关于java.lang.NoSuchFieldError:用于Eclipse中的简单hbase Java客户机的IBM_JAVA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆