Before you perform operations on resources in Object Storage Service (OSS), you must install OSS SDK for Java. This topic describes how to install OSS SDK for Java in various scenarios. Install OSS SDK for Java based on your requirements.

Prerequisites

Java 1.7 or later is installed.

You can run the java -version command to check the Java version.

Download OSS SDK for Java

Install OSS SDK for Java

You can use one of the following methods to install OSS SDK for Java.
Note Select an appropriate version of OSS SDK for Java based on your requirements. We recommend that you use the latest version.
  • Method 1: (Recommended) Add dependencies to your Maven project

    To use OSS SDK for Java in Maven, you need to only add the required dependencies to the pom.xml file. For OSS SDK for Java 3.15.1, add the following content to <dependencies>:

    <dependency>
        <groupId>com.aliyun.oss</groupId>
        <artifactId>aliyun-sdk-oss</artifactId>
        <version>3.15.1</version>
    </dependency>

    For OSS SDK for Java 9 or later, you must add jaxb-related dependencies. The following code provides an example on how to add jaxb-related dependencies:

    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.1</version>
    </dependency>
    <dependency>
        <groupId>javax.activation</groupId>
        <artifactId>activation</artifactId>
        <version>1.1.1</version>
    </dependency>
    <!-- no more than 2.3.3-->
    <dependency>
        <groupId>org.glassfish.jaxb</groupId>
        <artifactId>jaxb-runtime</artifactId>
        <version>2.3.3</version>
    </dependency>
  • Method 2: Import the JAR package to your Eclipse project

    For OSS SDK for Java 3.15.1, perform the following steps to import the JAR package to your Eclipse project:

    1. Download the OSS SDK for Java package.
    2. Decompress the package.
    3. Copy the aliyun-sdk-oss-3.15.1.jar file and all files in the lib directory to your project.
    4. Right-click your project name in Eclipse and choose Properties > Java Build Path > Add JARs.
    5. Select all JAR files that you copied and import the files to Libraries.
  • Method 3: Import the JAR package to your IntelliJ IDEA project

    For OSS SDK for Java 3.15.1, perform the following steps to import the JAR package to your IntelliJ IDEA project:

    1. Download the OSS SDK for Java package.
    2. Decompress the package.
    3. Copy the aliyun-sdk-oss-3.15.1.jar file and all JAR files in the lib directory to your project.
    4. Right-click your project name in IntelliJ IDEA and choose File > Project Structure > Modules > Dependencies > + > JARs or directories.
    5. Select all JAR files that you copied and import the files to External Libraries.