Help Center/ MapReduce Service/ Developer Guide (LTS)/ Obtaining Sample Projects from Huawei Mirrors
Updated on 2022-11-18 GMT+08:00

Obtaining Sample Projects from Huawei Mirrors

Procedure

Building a sample project includes the following operations:

  1. Download the Maven project source code and configuration files of the sample project. For details, see Obtaining Sample Projects.
  2. Configure the Maven mirror repository of the SDK in Huawei Mirrors. For details, see Configuring Huawei Open Source Mirrors.
  3. Build a complete Maven project based on user requirements.

Obtaining Sample Projects

You can download MRS sample projects at https://github.com/huaweicloud/huaweicloud-mrs-example.

Figure 1 Downloading sample code

Switch the branch to the version that matches the MRS cluster,for example mrs-3.1.2. Download the package to a local directory, and decompress the package to obtain the sample code project of each component.

Configuring Huawei Open Source Mirrors

Huawei provides Huawei Mirrors for you to download all dependency JAR files of sample projects. However, you need to download the rest dependency open source JAR files from the Maven central repository or other custom repository address.

Perform the following steps to configure the open source mirror warehouse.

  1. JDK 1.8 or later and Maven 3.0 or later have been installed.
  2. Download the settings.xml file provided by Huawei Mirrors, and overwrite the <Maven installation directory>/conf/settings.xml file with the downloaded file.

    If the file cannot be downloaded, search for HuaweiCloud SDK at Huawei Mirrors, click HuaweiCloud SDK, and perform operations as prompted.

  3. If you do not want to overwrite the Maven configuration file, you can manually modify the settings.xml configuration file or the pom.xml file of the component sample project to configure the mirror repository address. The configuration methods are as follows:

    • Configuration method 1

      Add the following open source mirror repository address to mirrors in the settings.xml configuration file.

      <mirror>
          <id>repo2</id>
          <mirrorOf>central</mirrorOf>
          <url>https://repo1.maven.org/maven2/</url>
      </mirror>

      Add the following mirror repository address to profiles in the settings.xml configuration file.

      <profile>
          <id>huaweicloudsdk</id>
          <repositories>
              <repository>
                  <id>huaweicloudsdk</id>
                  <url>https://repo.huaweicloud.com/repository/maven/huaweicloudsdk/</url>
                  <releases><enabled>true</enabled></releases>
                  <snapshots><enabled>true</enabled></snapshots>
              </repository>
          </repositories>
      </profile>

      Add the following mirror repository address to the activeProfiles node in the settings.xml file.

      <activeProfile>huaweicloudsdk</activeProfile>
      • Huawei Mirrors does not provide third-party open source JAR files. After configuring Huawei open source mirrors, you need to separately configure third-party Maven mirror repository address.
      • When using the IntelliJ IDEA development tool, you can choose File > Settings > Build, Execution, Deployment > Build Tools > Maven to view the directory where the settings.xml file is stored.
    • Configuration method 2

      Add the following mirror repository address directly to the pom.xml file in the secondary development sample project.

          <repositories>
      
              <repository>
                  <id>huaweicloudsdk</id>
                  <url>https://mirrors.huaweicloud.com/repository/maven/huaweicloudsdk/</url>
                  <releases><enabled>true</enabled></releases>
                  <snapshots><enabled>true</enabled></snapshots>
              </repository>
      
              <repository>
                  <id>central</id>
                  <name>Maven Central</name>
                  <url>https://repo1.maven.org/maven2/</url>
              </repository>
      
          </repositories>

  4. Configure the default Maven code and JDK. Add the following information to profiles in the settings.xml configuration file:

    <profile>
    <id>JDK1.8</id>
    <activation>
    <activeByDefault>true</activeByDefault>
    <jdk>1.8</jdk>
    </activation>
    <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <maven.compiler.encoding>UTF-8</maven.compiler.encoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
    </properties>
    </profile>