Updated on 2023-08-31 GMT+08:00

Configuring and Importing Sample Projects

Background

Obtain the HBase development example project . Import the project to IntelliJ IDEA for learning.

Prerequisites

  • Ensure that the difference between the local PC time and the MRS cluster time is less than 5 minutes. If the time difference cannot be determined, contact the system administrator. You can view the MRS cluster time in the bottom-right corner on FusionInsight Manager.
  • You have prepared the development environment and MRS cluster configuration files. For details, see Preparing the Configuration Files of the Running Environment.

Procedure

  1. Obtain the sample project from the src directory in the directory where the sample code is decompressed by referring to Obtaining Sample Projects from Huawei Mirrors. You can select a sample based on the actual service scenario. For details about the samples, see HBase Sample Project.
  2. If you need to debug the sample code on the local Windows PC, place the configuration files required by each sample project as required in Table 1.

    Table 1 Configuration files required by each sample project

    Sample Project Location

    Configuration/authentication files to be placed

    hbase-examples/hbase-example (single cluster)

    Save the core-site.xml, hbase-site.xml, and hdfs-site.xml files obtained in the Preparing the Configuration Files of the Running Environment to the ../src/main/resources/conf directory of the sample project.

    hbase-examples/hbase-example (multi-cluster)

    Place the configuration file of a cluster with the same user name in the mutual trust scenario to the ../src/main/resources/hadoopDomain directory, and place the configuration file of the other cluster to the ../src/main/resources/hadoop1Domain directory.

    The configuration files are core-site.xml, hbase-site.xml, and hdfs-site.xml obtained in section Preparing the Configuration Files of the Running Environment.

    hbase-examples/hbase-rest-example

    -

    hbase-examples/hbase-thrift-example

    Save the core-site.xml, hbase-site.xml, and hdfs-site.xml files obtained in the Preparing the ThriftServer Instance Configuration Files to the ../src/main/resources/conf directory of the sample project.

    hbase-examples/hbase-zk-example

    Place the following files in the ../src/main/resources/conf directory of the sample project:

  3. After the IntelliJ IDEA and JDK are installed, configure the JDK in IntelliJ IDEA.

    1. Start the IntelliJ IDEA and click Configure.
      Figure 1 Quick Start
    2. Click Structure for New Projects from the drop-down list.
      Figure 2 Configure
    3. On the displayed Project Structure for New Projects page, select SDKs and click the plus sign (+) to add the JDK.
      Figure 3 Project Structure for New Projects
    4. In the Select Home Directory for JDK window that is displayed, select the JDK directory, and click OK.
      Figure 4 Select Home Directory for JDK
    5. After selecting the JDK, click OK to complete the configuration.
      Figure 5 Complete JDK configuration

      The operations vary by the IDEA version. The operation procedure varies according to the actual version.

  4. Import the example project to the IntelliJ IDEA development environment.

    1. Start the IntelliJ IDEA, and click Import Project on the Open or Import.

      For the IDEA tool that has been used, you can choose File > Import project... on the main interface to import the sample project.

      Figure 6 Open or Import (Quick Start page)
    2. Select the example project folder hbase-example, and click OK.
      Figure 7 Select File or Directory to Import
    3. After the import, the imported sample project is displayed on the IDEA home page.
      Figure 8 Successfully importing the sample project
    4. Right-click pom.xml and choose Add as Maven Project from the shortcut menu to add the project as a Maven Project. If the pom.xml icon is as shown in , go to the next step.
      Figure 9 Add as Maven Project

      In this case, the IDEA can identify the project as a Maven project.

      Figure 10 Sample project displayed in IDEA as a Maven project

  5. Set the Maven version used by the project.

    1. Choose File > Settings... from the main menu of IntelliJ IDEA.
      Figure 11 Settings
    2. Choose Build,Execution,Deployment > Maven and set Maven home directory to the Maven version installed on the local host.
      Set User settings file and Local repository parameters based on the site requirements, and choose Apply > OK.
      Figure 12 Selecting the local Maven installation directory

  6. Set the IntelliJ IDEA text file coding format to prevent garbled characters.

    1. On the IntelliJ IDEA menu bar, choose File > Settings....
      Figure 13 Settings
    2. In the navigation tree of the Settings page, choose Editor > File Encodings, and select UTF-8 for Global Encoding and Project Encoding.
      Figure 14 File Encodings
    3. Click Apply and OK to complete the encoding configuration.