版本:
Hadoop:2.0.0-cdh4.3.1
HBase:0.94.6-cdh4.3.1
我正在运行cloudera quick start vm,这是我的小型远程HBase Java客户端(HbaseClient.java),它所做的就是:
public static void main(String[] args) throws IOException {
Configuration config = HBaseConfiguration.create();
HTable table = new HTable(config, "s1");
System.out.println(table.getTableName());
}
当我运行我的Java客户端时,我收到此错误:
log4j:WARN No appenders could be found for logger (org.apache.hadoop.metrics2.lib.MutableMetricsFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
2013-08-25 00:01:56.684 java[39082:1703] Unable to load realm info from SCDynamicStore
Exception in thread "main" org.apache.hadoop.hbase.client.NoServerForRegionException: Unable to find region for s1,,99999999999999 after 10 tries.
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.locateRegionInMeta(HConnectionManager.java:980)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.locateRegion(HConnectionManager.java:885)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.locateRegionInMeta(HConnectionManager.java:987)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.locateRegion(HConnectionManager.java:889)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.locateRegion(HConnectionManager.java:846)
at org.apache.hadoop.hbase.client.HTable.finishSetup(HTable.java:271)
at org.apache.hadoop.hbase.client.HTable.<init>(HTable.java:211)
at org.apache.hadoop.hbase.client.HTable.<init>(HTable.java:170)
at com.***************.api.HBaseClient.main(HBaseClient.java:24)
我通过代码调试,很难找到客户端是否在资源文件夹中使用我的hbase-site.xml。我甚至在hbase-site.xml中输入了错误的格式内容,Java客户端也遇到了同样的错误。所以我认为它没有使用它。资源文件夹不是CLASSPATH的一部分吗?有没有办法检查hbase-site.xml是否被使用,如果没有使用,如何让我的客户端使用它。
答案 0 :(得分:4)
首先把你的配置文件,意思是core-site.xml hbase-site.xml hdfs-site.xml,放在src / main / resources中,把它变成一个源文件夹(在eclipse下点击右边的文件夹 - &gt; Build路径 - &gt;用作源文件夹) 然后试试这段代码
public class HbaseConfig {
private static final Logger LOG = LoggerFactory.getLogger(HbaseConfig.class);
public static org.apache.hadoop.conf.Configuration getHHConfig() {
Configuration conf = HBaseConfiguration.create();
InputStream confResourceAsInputStream = conf.getConfResourceAsInputStream("hbase-site.xml");
int available = 0;
try {
available = confResourceAsInputStream.available();
} catch (Exception e) {
//for debug purpose
LOG.debug("configuration files not found locally");
} finally {
IOUtils.closeQuietly(confResourceAsInputStream);
}
if (available == 0 ) {
conf = new Configuration();
conf.addResource("core-site.xml");
conf.addResource("hbase-site.xml");
conf.addResource("hdfs-site.xml");
}
return conf;
}
}
最后在您的代码中
public static void main(String[] args) throws IOException {
Configuration config = HbaseConfig.getHHConfig();
HTable table = new HTable(config, "s1");
System.out.println(table.getTableName());
}
答案 1 :(得分:1)
您必须确保* site.xml文件是从hadoop实例复制的,并且在eclipse类路径中可用。只需添加包含xmls的文件夹作为源文件夹即可。