Configuring and Importing a Sample Project
Background
You can obtain the HBase development sample project and import the project to IntelliJ IDEA.
Prerequisites
- Ensure that the difference between the time on the local PC and the cluster time is less than 5 minutes. If the time difference cannot be determined, contact the system administrator. You can view the time of the cluster in the lower-right corner on the FusionInsight Manager page.
- You have prepared the development environment and MRS cluster configuration files. For details, see Preparing the Configuration Files for Connecting to the Cluster.
Procedure
- Obtain the sample project from the src directory in the directory where the sample code is decompressed by referring to Obtaining the MRS Application Development Sample Project. You can select a sample based on the actual service scenario. For details about the samples, see HBase Sample Project.
- If you need to debug the sample code on the local Windows PC, place the configuration files and authentication files required by each sample project as required in Table 1.
Table 1 Configuration files and authentication files required by each sample project Sample Project Location
Configuration/Authentication Files
hbase-examples/hbase-example (for single cluster)
Place the following files in the ../src/main/resources/conf directory of the sample project:
- Configuration files: core-site.xml, hbase-site.xml, and hdfs-site.xml obtained in Preparing the Configuration Files of the Running Environment
- Authentication files: user.keytab and krb5.conf obtained in Preparing User Information for Cluster Authentication
hbase-examples/hbase-example (mutual trusted clusters)
Place the authentication credential of the shared user and the configuration files of one cluster to the ../src/main/resources/hadoopDomain directory, and place the configuration files of the other cluster to the ../src/main/resources/hadoop1Domain directory.
- Configuration files: core-site.xml, hbase-site.xml, and hdfs-site.xml obtained in Preparing the Configuration Files of the Running Environment
- Authentication files: user.keytab and krb5.conf obtained in Preparing User Information for Cluster Authentication
hbase-examples/hbase-rest-example
Place the keytab authentication files user.keytab and krb5.conf obtained in Preparing User Information for Cluster Authentication to ../src/main/resources/conf. If the conf directory does not exist, create one.
hbase-examples/hbase-thrift-example
Place the following files in ../src/main/resources/conf of the sample project:
- Configuration files: hdfs-site.xml, core-site.xml, and hbase-site.xml obtained in Preparing the ThriftServer Instance Configuration Files
- Authentication files: user.keytab and krb5.conf obtained in Preparing User Information for Cluster Authentication
hbase-examples/hbase-zk-example
Place the following files in the ../src/main/resources directory of the sample project:
- Configuration files: core-site.xml, hbase-site.xml, and hdfs-site.xml obtained in Preparing the Configuration Files of the Running Environment
- Authentication files: user.keytab and krb5.conf obtained in Preparing User Information for Cluster Authentication
- Ensure that the zoo.cfg and jaas.conf files required for Authentication for Accessing Multiple ZooKeepers are placed in the directory.
- After the IntelliJ IDEA and JDK tools are installed, configure the JDK in IntelliJ IDEA.
- Start IntelliJ IDEA and choose Configure.
Figure 1 Quick Start
- Select Structure for New Projects from the drop-down list.
Figure 2 Configure
- On the displayed Project Structure for New Projects page, select SDKs, click the plus sign (+), and click JDK.
Figure 3 Project Structure for New Projects
- On the Select Home Directory for JDK page that is displayed, select the JDK directory and click OK.
Figure 4 Select Home Directory for JDK
- After selecting the JDK, click OK to complete the configuration.
Figure 5 Completing the JDK configuration
The operation procedure may vary according to the IDEA version.
- Start IntelliJ IDEA and choose Configure.
- Import the sample project to the IntelliJ IDEA development environment.
- Start the IntelliJ IDEA, and click Open or Import on the quick start page.
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)
- Select the sample project folder hbase-example and click OK.
Figure 7 Selecting a file or directory to import
- After the import is complete, check that the imported sample projects are displayed on the IDEA home page.
Figure 8 Successfully importing sample projects
- 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 displayed as
, go to the next step.
Figure 9 Adding as a 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
- Start the IntelliJ IDEA, and click Open or Import on the quick start page.
- Set the Maven version used by the project.
- Choose File > Settings... from the main menu of IntelliJ IDEA.
Figure 11 Settings
- Choose Build, Execution, Deployment > Maven and set Maven home directory to the Maven version installed on the local PC.
Set User settings file and Local repository as you need, and click Apply > OK.Figure 12 Selecting the local Maven installation directory
- Choose File > Settings... from the main menu of IntelliJ IDEA.
- Set the IntelliJ IDEA text file coding format to prevent garbled characters.
- Choose File > Settings... from the main menu of IntelliJ IDEA.
Figure 13 Settings
- In the navigation tree of the Settings page, choose Editor > File Encodings, and select UTF-8 for both Global Encoding and Project Encoding.
Figure 14 File encodings
- Click Apply and OK to complete the configuration.
- Choose File > Settings... from the main menu of IntelliJ IDEA.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.