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

Obtaining and Installing the SDK

Installing Java SDKs

You can install Java SDKs in either of the following ways:

Obtaining DLI SDKs

On the displayed DLI SDK DOWNLOAD page, click the target link to obtain the desired SDK installation package.

Obtain the dli-sdk-java-x.x.x.zip package and decompress it. The following table shows the directory structure of the package.

Table 1 Directory structure

Parameter

Description

jars

SDK and its dependent JAR packages.

maven-install

Script and JAR package that are installed in the local Maven repository.

dli-sdk-java.version

Java SDK version description.

Method 1: Installing DLI SDK Dependencies Using Maven

You are advised to install dependencies using Maven to use Huawei Cloud Java SDKs.

  • Installing service-level SDK dependencies
    1. Download and install Apache Maven on your operating system.
    2. After installing and configuring Maven, run the mvn -v command. Maven is installed successfully if the following information is displayed.

    3. Add dependencies to an existing Maven project or use an integrated development environment (IDE) to create a Maven project.

      For example, to create a Maven project using IntelliJ IDEA, perform the following steps (skip them if you already have a Maven project):

      1. Start IntelliJ IDEA.
      2. Choose File > New > project...
      3. In the displayed New Project dialog box, click Maven and then Next.
      4. Specify GroupId and ArtifactId, and click Next.
      5. Specify Project name and Project location, and click Finish.
    4. Add dependency items to the pom.xml file of the Maven project.

      Taking the example of importing the latest version of the SDK, obtain the latest version of the SDK package and replace the version in the code.

      1
      2
      3
      4
      5
       <dependency>
          <groupId>com.huawei.dli</groupId>
          <artifactId>huaweicloud-dli-sdk-java</artifactId>
          <version>x.x.x</version>
       </dependency>
      
  • Installing SDK dependencies of other services

    DLI depends on SDKs (for example, OBS SDK), which can be downloaded by configuring the Maven image source repository of Huawei Cloud.

    • (Recommended) Using the Huawei image source as the main repository:

      For details about how to configure the Huawei Maven image source, visit Huawei open source image site, select Huawei SDK, and click HuaweiCloud SDK.

      If you build a project with Maven, modify the settings.xml file by adding the following content:

      1. Add the following content to the profiles node:
        <profile>
            <id>MyProfile</id>
            <repositories>
                <repository>
                    <id>HuaweiCloudSDK</id>
                    <url>https://repo.huaweicloud.com/repository/maven/huaweicloudsdk/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>HuaweiCloudSDK</id>
                    <url>https://repo.huaweicloud.com/repository/maven/huaweicloudsdk/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
      2. Add the following information to the mirrors node:
        <mirror>
            <id>huaweicloud</id>
            <mirrorOf>*,!HuaweiCloudSDK</mirrorOf>
            <url>https://repo.huaweicloud.com/repository/maven/</url>
        </mirror>
      3. Add the activeProfiles tag to activate the configurations.
        <activeProfiles>
          <activeProfile>MyProfile</activeProfile>
        </activeProfiles>
    • Use a non-Huawei image source as the main repository (for example, a user-defined image source) to use HuaweiCloud SDKs:

      If you build a project with Maven, modify the settings.xml file as follows:

      <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
          <servers>
      	 <server>
            <id>demo-releases</id>    
            <username>deployment</username>    
            <password><![CDATA[xxx]]></password>  
          </server>    
        </servers>
        <mirrors>
          <mirror>     
            <id>demo-releases</id>     
            <mirrorOf>*,!HuaweiCloudSDK</mirrorOf>     
            <url>http://maven.demo.com:8082/demo/content/groups/public</url>     
          </mirror>    
        </mirrors>
        <profiles>
          <profile>    
            <id>demo</id>
            <activation>
              <activeByDefault>true</activeByDefault>
              <jdk>1.8</jdk>
            </activation> 
            <properties>
              <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>
            <repositories>    
               <repository>    
                <id>demo-releases</id>    
                <url>http://demo-releases</url>    
                <releases>
                  <enabled>true</enabled>
                </releases>    
                <snapshots>
                  <enabled>true</enabled>
                </snapshots>    
              </repository> 
            </repositories>
            <pluginRepositories>    
               <pluginRepository>    
                  <id>demo-releases</id>    
                  <url>http://demo-releases</url>    
                  <releases>
                    <enabled>true</enabled>
                  </releases>    
                  <snapshots>
                    <enabled>true</enabled>
                  </snapshots>    
                </pluginRepository>
            </pluginRepositories>    
          </profile>
          <profile>
            <id>huaweicloudrepo</id>
            <repositories>
              <repository>
                <id>HuaweiCloudSDK</id>
                <url>https://repo.huaweicloud.com/repository/maven/huaweicloudsdk/</url>
                <releases>
                  <enabled>true</enabled>
                </releases>
                <snapshots>
                  <enabled>false</enabled>
                </snapshots>
              </repository>
            </repositories>
            <pluginRepositories>
              <pluginRepository>
                <id>HuaweiCloudSDK</id>
                <url>https://repo.huaweicloud.com/repository/maven/huaweicloudsdk/</url>
                <releases>
                  <enabled>true</enabled>
                </releases>
                <snapshots>
                  <enabled>false</enabled>
                </snapshots>
              </pluginRepository>
            </pluginRepositories>
          </profile> 
        </profiles>
        <activeProfiles>
          <activeProfile>demo</activeProfile>
          <activeProfile>huaweicloudrepo</activeProfile>
        </activeProfiles>
      </settings>

Method 2: Installing the SDK by Importing JAR Files to Eclipse

To import JAR files into an Eclipse integrated development environment project, follow these steps.

  1. Download Eclipse IDE for Java Developers of the latest version from the Eclipse's official website and install it. Configure the JDK in Eclipse.

    1. Create a project and select the correct JRE version. For details, see Figure 1.
      Figure 1 Creating a project

  2. Configure and import the SDK JAR package.

    1. Right-click JRE System Library and choose Build Path > Configure Build Path from the shortcut menu. For details, see Figure 2.
      Figure 2 Configuring the project path
    2. Click Add External JARs, select the downloaded JAR package obtained in Obtaining DLI SDKs, and click OK.
      Figure 3 Selecting the SDK JAR package