Updated on 2026-04-09 GMT+08:00

Initializing HBase Configurations

Function

HBase obtain configuration items by using the login method. The configuration items include user login information and security authentication information.

Example Codes

  • For versions earlier than MRS 3.3.0-LTS:

    The following code snippet belongs to the init method in the TestMain class of the com.huawei.bigdata.hbase.examples package.

    private static void init() throws IOException {
        // Default load from conf directory
        conf = HBaseConfiguration.create();
        //In Windows environment
        String userdir = TestMain.class.getClassLoader().getResource("conf").getPath() + File.separator;
        //In Linux environment
        //String userdir = System.getProperty("user.dir") + File.separator + "conf" + File.separator;
        conf.addResource(new Path(userdir + "core-site.xml"), false);
        conf.addResource(new Path(userdir + "hdfs-site.xml"), false);
        conf.addResource(new Path(userdir + "hbase-site.xml"), false);
      }
  • For MRS 3.3.0-LTS or later versions:

    The following code snippet belongs to the createClientConf method in the createClientConf class of the com.huawei.bigdata.hadoop.security.examples package.

    public static Configuration createClientConf() {
        // In Windows environment
        String userDir = Utils.class.getClassLoader().getResource(CONF_DIRECTORY).getPath() + File.separator;
        // In Linux environment
        // String userDir = System.getProperty("user.dir") + File.separator + CONF_DIRECTORY + File.separator;
        return createConfByUserDir(userDir);
    }
    public static Configuration createConfByUserDir(String userDir) {
        // Default load from conf directory
        Configuration conf = HBaseConfiguration.create();
        if (userDir == null || userDir.isEmpty()) {
            return conf;
        }
        conf.addResource(new Path(userDir + CLIENT_CORE_FILE), false);
        conf.addResource(new Path(userDir + CLIENT_HDFS_FILE), false);
        conf.addResource(new Path(userDir + CLIENT_HBASE_FILE), false);
        return conf;
    }