Updated on 2024-06-21 GMT+08:00

Compiling and Running an Application When No Client Is Installed

Scenario

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.

Procedure

  1. Export a JAR file.

    1. Right-click the sample project and choose Export from the shortcut menu.
      Figure 1 Exporting a JAR file
    2. Select JAR file and click Next.
      Figure 2 Selecting JAR file
    3. Select the src directory, and export the JAR file to the specified location. Click Next twice.
      Figure 3 Selecting a path for exporting the JAR file
    4. Click Finish. Exporting the JAR file is complete.

  2. Prepare the required 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 file in lib in the sample project and the JAR file exported in 1 to the lib directory on Linux. Upload the configuration file in conf in the sample project to the conf directory on Linux.
    2. In the /opt/test root directory, create the run.sh script, modify the following content, and save the file:
      #!/bin/sh
      BASEDIR=`pwd`
      SECURE=""
      if [ $# -eq 1 ]; then
        SECURE="-Dzookeeper.clientCnxnSocket=org.apache.zookeeper.ClientCnxnSocketNetty -Dzookeeper.client.secure=true"
      fi
      cd ${BASEDIR}
      for file in ${BASEDIR}/lib/*.jar
      do
      i_cp=$i_cp:$file
      echo "$file"
      done
      for file in ${BASEDIR}/conf/*
      do
      i_cp=$i_cp:$file
      done
      java -cp .${i_cp} ${SECURE} com.huawei.cloudtable.hbase.examples.TestMain

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

    • HBase clusters with the encryption stream disabled

      sh run.sh

    • HBase clusters with the encryption stream enabled

      sh run.sh secure

      If you use other methods to access an HBase cluster with the encryption stream enabled, you need to add the parameter "-Dzookeeper.clientCnxnSocket=org.apache.zookeeper.ClientCnxnSocketNetty -Dzookeeper.client.secure=true".