Updated on 2022-06-01 GMT+08:00

Compiling and Running an Application When No Client Is Installed

HBase applications can run in a Linux environment where an HBase client is not installed. After application code development is complete, you can upload a JAR file to the Linux environment to run applications.

Prerequisites

  • You have installed a JDK in the Linux environment. The version of the JDK must be consistent with that of the JDK used by Eclipse to export the JAR file.
  • If the host where the Linux environment resides is not a node in the cluster, the mapping between the host name and the IP address must be set in the hosts file on the node where the Linux environment resides. The host names and IP addresses must be mapped one by one.

Procedure

  1. Modify the sample by following instructions in Compiling and Running an Application When a Client Is Installed.
  2. Run the mvn package command to generate a JAR file, for example, hbase-examples-2.0.jar, and obtain it from the target directory in the project directory.
  3. Prepare the dependency JAR file and configuration file.

    1. In the Linux environment, create a directory, for example, /opt/test, and create subdirectories lib and conf. Upload the JAR packages in the /opt/client/HBase/hbase/lib directory on any master node in the cluster and the JAR packages exported in 2 to the lib directory in the new /opt/test directory in the Linux environment. Copy the hbase-site.xml, hdfs-site.xml, and core-site.xml files in the /opt/client/HBase/hbase/conf directory of any master node in the cluster to the conf directory in /opt/test.
    2. Copy the krb5.conf and user.keytab files obtained in Preparing a Development User to the /opt/test/conf directory, and create the hbaseclient.properties file. In the file, user.name corresponds to the new user hbaseuser, the userKeytabName and krb5ConfName paths correspond to the names of the authentication-related files obtained in Preparing a Development User (skip this step if Kerberos authentication is not enabled for the cluster).
      user.name=hbaseuser
      userKeytabName=user.keytab
      krb5ConfName=krb5.conf
    3. In the /opt/test root directory, create the run.sh script, modify the following content, and save the file.
      com.huawei.bigdata.hbase.examples.TestMain is used as an example. Use the actual code instead.
      #!/bin/sh
      BASEDIR=`pwd`
      cd ${BASEDIR}
      for file in ${BASEDIR}/lib/*.jar
      do
      i_cp=$i_cp:$file
      echo "$file"
      done
      if [ -d ${BASEDIR}/lib/client-facing-thirdparty ]; then
      for file in ${BASEDIR}/lib/client-facing-thirdparty/*.jar
      do
      i_cp=$i_cp:$file
      done
      fi
      java -cp ${BASEDIR}/conf:${i_cp} com.huawei.bigdata.hbase.examples.TestMain

  4. Go to /opt/test and run the following command to run the JAR file:

    sh run.sh