Updated on 2022-07-11 GMT+08:00

Compiling and Running an Application When a Client Is Installed

Scenario

In a Linux environment where an HBase client is installed, you can upload the JAR package to the Linux and then run an application after the code development is complete.

Prerequisites

  • You have installed the HBase client.
  • If the host where the client is installed is not a node in the cluster, set the mapping between the host name and the IP address in the hosts file on the node where the client locates. The host name and IP address must be in one-to-one mapping.
  • The JDK has been installed and Java environment variables have been correctly configured before Windows commissioning and compilation.

Procedure

  1. Export a JAR package.

    You can build a JAR file in either of the following ways:

    • Method 1:

      Choose Maven > Sample projectname > Lifecycle > clean, double click clean to run the clean command of Maven.

      Choose Maven > Sample project name > Lifecycle > install, double click install to run the install command of Maven.
      Figure 1 Maven tools: clean and installl
    • Method 2: Go to the directory where the pom.xml file is located in the Terminal window in the lower part of the IDEA, and run the mvn clean install command to compile the pom.xml file.
      Figure 2 Enter mvn clean compile in the IDEA Terminal text box.

      After the compilation is completed, the message "Build Success" is displayed, the target directory is generated, and the generated JAR file is stored in the target directory.

      Figure 3 When the compilation is completed, the JAR file is generated.

  1. Export the JAR file on which the sample project depends.

    Access the directory where the pom.xml file is located in the Terminal window in the lower part of IDEA or by using other command line tools.

    Run the command mvn dependency:copy-dependencies -DoutputDirectory=lib.

    The lib folder is generated in the directory where the pom.xml file is located. The lib folder contains the JAR files on which the sample project depends.

  2. Run the JAR package.

    1. Before running the JAR package on the Linux client, run the following command to go to the client directory:

      cd $BIGDATA_CLIENT_HOME

      $BIGDATA_CLIENT_HOME is the installation directory of the HBase client.

    2. Then run the following command:

      source bigdata_env

      After the multi-instance function is enabled, run the following command to switch to the client of the specified service instance before performing application development for the HBase service instance.

      For example, for HBase2, run the source /opt/client/HBase2/component_env command.

    3. Upload the JAR file (non-dependent JAR file) of the sample project generated in the application development environment to the $BIGDATA_CLIENT_HOME/HBase/hbase/lib directory in the client running environment. Check the $BIGDATA_CLIENT_HOME/HBase/hbase/conf directory based on the sample project README.md, and copy the configuration file and authentication file in the sample project to this directory.
    4. Go to the $BIGDATA_CLIENT_HOME/HBase/hbase directory and run the following command to run the JAR package. The task is complete.

      hbase com.huawei.bigdata.hbase.examples.TestMain

      In the preceding command, hbase com.huawei.bigdata.hbase.examples.TestMain is used as an example.