[转] HBase异常:hbase-default.xml file seems to be for an old version of HBase
【From】 https://blog.yoodb.com/yoodb/article/detail/157
使用HBase Java Client连接HBase服务端创建Configuration对象时遇到了此类错误,“hbase-default.xml file seems to be for and old version of HBase的异常”,经过查询资料总结经验。
分析异常出现的原因
HBase客户端创建Configuration对象时,需要使用hbase-*.jar包,其中*部分标识了连接的HBase版本号:
[root@xxxxxx]$ ls hbase-*.jar hbase-0.92.1.jar
在hbase-*.jar包的hbase-default.xml中,有一个关于HBase默认版本号的配置项如下:
<property skipInDoc="true"> <name>hbase.defaults.for.version</name> <value>0.92.1</value> <description> This defaults file was compiled for version 0.92.1. This variable is used to make sure that a user doesn't have an old version of hbase-default.xml on the classpath. </description> </property>
当客户端启动时,首先会检测此包中所指定的版本号以及hbase-default.xml中设置的hbase.defaults.for.version版本号是否一致。正常情况下二者是一致,不会抛出Exception。
如果指定版本号小于hbase.defaults.for.version指定版本号,就会抛出如下异常:
Exception in thread "main" java.lang.RuntimeException: hbase-default.xml file seems to be for and old version of HBase (@@@VERSION@@@), this version is 0.92.1 at org.apache.Hadoop.hbase.HBaseConfiguration.checkDefaultsVersion(HBaseConfiguration.java:68) at org.apache.hadoop.hbase.HBaseConfiguration.addHbaseResources(HBaseConfiguration.java:100) at org.apache.hadoop.hbase.HBaseConfiguration.create(HBaseConfiguration.java:111) at org.apache.hadoop.hbase.util.HBaseConfTool.main(HBaseConfTool.java:38) Exception in thread "main" java.lang.RuntimeException: hbase-default.xml file seems to be for and old version of HBase (@@@VERSION@@@), this version is 0.92.1 ...
解决方式
异常情况一:
Caused by: java.lang.RuntimeException: hbase-default.xml file seems to be for and old version of HBase (*.**.*), this version is 0.92.1 at org.apache.hadoop.hbase.HBaseConfiguration.checkDefaultsVersion(HBaseConfiguration.java:68) at org.apache.hadoop.hbase.HBaseConfiguration.addHbaseResources(HBaseConfiguration.java:100)
原因是hbase-default.xml中的hbase.defaults.for.version配置项与hbase-*.jar名中指定版本号不一致,打开工程目录下的hbase-site.xml,将hbase.defaults.for.version.skip配置为true,忽略默认版本的检查代码如下:
<property> <name>hbase.defaults.for.version.skip</name> <value>true</value> <description> Set to true to skip the 'hbase.defaults.for.version' check. Setting this to true can be useful in contexts other than the other side of a maven generation; i.e. running in an ide. You'll want to set this boolean to true to avoid seeing the RuntimException complaint: "hbase-default.xml file seems to be for and old version of HBase (0.92.1), this version is X.X.X-SNAPSHOT" </description> </property>
异常情况二:
Caused by: java.lang.RuntimeException: hbase-default.xml file seems to be for and old version of HBase (null), this version is 0.92.1 at org.apache.hadoop.hbase.HBaseConfiguration.checkDefaultsVersion(HBaseConfiguration.java:68) at org.apache.hadoop.hbase.HBaseConfiguration.addHbaseResources(HBaseConfiguration.java:100)
加载hbase-default.xml失败没有获取默认的版本号,因实际情况而定试一试删除Java的工程目录下的hbase-default.xml文件。
异常情况三:(maven下载jar包导致)
Caused by: java.lang.RuntimeException: hbase-default.xml file seems to be for and old version of HBase (@@@VERSION@@@), this version is 0.92.1 at org.apache.hadoop.hbase.HBaseConfiguration.checkDefaultsVersion(HBaseConfiguration.java:68) at org.apache.hadoop.hbase.HBaseConfiguration.addHbaseResources(HBaseConfiguration.java:100)
hbase-default.xml中的hbase.defaults.for.version配置项在打包时没有被正常替换成maven指定的版本号打开HBase maven工程的pom.properties文件,确定是否指定了version=0.92.1这一配置选项,如果没有,加上后进行重新包,也可以参考第一种异常解决方案操作。