Obtaining and Installing the SDK
Installing Java SDKs
You can install Java SDKs in either of the following ways:
- Import Maven dependencies, which applies to Java projects managed by Maven. For details, see Method 1: Installing DLI SDK Dependencies Using Maven.
- Import JAR files into the integrated development environment, which is suitable for projects that use Eclipse as their IDE. For details, see Method 2: Installing the SDK by Importing JAR Files to Eclipse.
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.
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
- Download and install Apache Maven on your operating system.
- After installing and configuring Maven, run the mvn -v command. Maven is installed successfully if the following information is displayed.
- 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):
- Start IntelliJ IDEA.
- Choose File > New > project...
- In the displayed New Project dialog box, click Maven and then Next.
- Specify GroupId and ArtifactId, and click Next.
- Specify Project name and Project location, and click Finish.
- 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:
- 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>
- Add the following information to the mirrors node:
<mirror> <id>huaweicloud</id> <mirrorOf>*,!HuaweiCloudSDK</mirrorOf> <url>https://repo.huaweicloud.com/repository/maven/</url> </mirror>
- Add the activeProfiles tag to activate the configurations.
<activeProfiles> <activeProfile>MyProfile</activeProfile> </activeProfiles>
- Add the following content to the profiles node:
- 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>
- (Recommended) Using the Huawei image source as the main repository:
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.
- Download Eclipse IDE for Java Developers of the latest version from the Eclipse's official website and install it. Configure the JDK in Eclipse.
- Create a project and select the correct JRE version. For details, see Figure 1.
- Configure and import the SDK JAR package.
- Right-click JRE System Library and choose Build Path > Configure Build Path from the shortcut menu. For details, see Figure 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
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot