This topic describes how to install Alibaba Cloud SDK for Java by using Maven dependencies or by SDK tools. To install the SDK for any Alibaba Cloud product, you must install the Alibaba Cloud SDK for Java core library.

Prerequisites

Before installing and using Alibaba Cloud SDK for Java, make sure that you have completed the following steps:
  • You have Installed a Java environment.

    Alibaba Cloud SDK for Java supports JDK 1.6 or later.

  • You have registered an Alibaba Cloud account and have created an AccessKey pair.

    For more information, see Create an AccessKey.

Method 1: Add Maven dependencies (recommended)

If you use Maven to manage Java projects, you can add Maven dependencies to pom.xmll file to install Alibaba Cloud SDK for Java. For more information about Maven dependencies of each cloud product, visit Alibaba Cloud SDK.

This topic uses Ecs SDK as an example. You only need to add the following two Maven dependencies to install the Alibaba Cloud SDK for Java core library and ECS Java SDK.

<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>aliyun-java-sdk-core</artifactId>
    <version>4.4.6</version>
</dependency>
<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>aliyun-java-sdk-ecs</artifactId>
    <version>4.17.6</version>
</dependency>

If Maven does not download the jar files from the central repository, you must add this dependency to pom.xml file, otherwise NoClassDefFoundError will occur.

<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.8.5</version>
</dependency>

Method 2: Import JAR files to the integrated development environment

If you are using Eclipse or IntelliJ as the integrated development environment, you can install Alibaba Cloud SDK for Java by directly importing the JAR files. You can visit Alibaba Cloud SDK for Java to download the JAR files of cloud products.

  • Use Eclipse

    Complete the following steps to install Alibaba Cloud SDK for Java in Eclipse:

    1. Copy the downloaded aliyun-java-sdk-xxx.jar file to your project folder.
    2. In Eclipse, open your project, right-click the project, and choose Properties from the shortcut menu.
    3. In the dialog box that appears, choose Java Build Path > Libraries > Add JARs to add the downloaded JAR files.
    4. Click Apply and Close.
  • Use IntelliJ
    Complete the following steps to install Alibaba Cloud SDK for Java in IntelliJ:
    1. Copy the downloaded aliyun-java-sdk-xxx.jar file to your project folder.
    2. In IntelliJ, open your project. In the menu bar, choose File > Project Structure.
    3. Click Apply and then click OK.