文档

安装

更新时间:

本文介绍阿里云Java SDK V2.0推荐的Maven安装方式。

环境准备

推荐使用Java 8及以上版本。

安装步骤

安装包含2个步骤,首先需要在pom.xml配置文件中添加阿里云Java SDK的Maven仓库,然后再添加媒体处理的依赖。

  1. 添加Maven仓库。

    <repositories>
           <repository>
               <id>sonatype-nexus-staging</id>
               <name>Sonatype Nexus Staging</name>
               <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
               <releases>
                   <enabled>true</enabled>
               </releases>
               <snapshots>
                   <enabled>true</enabled>
               </snapshots>
           </repository>
       </repositories>
  2. 添加依赖。

    阿里云Java SDK核心库以及媒体处理Java SDK的详细版本如下,下文示例代码以4.6.0版本Java SDK的核心库和3.3.45版本的媒体处理Java SDK为例:

    <dependency>
      <groupId>com.aliyun</groupId>
      <artifactId>mts20140618</artifactId>
      <version>5.0.0</version>
    </dependency>

    除上述库外,还有一个可选的JSON库依赖。在媒体处理的API中,很多参数都是JSON,您可以从Java的JSON库中选择熟悉的库。下文示例代码以1.2.68.noneautotype为例,pom.xml完整示例如下:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.alibaba</groupId>
        <artifactId>mps-java-sdk-demo</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>mps-java-sdk-demo</name>
        <description>Demo project for Spring Boot</description>
        <packaging>pom</packaging>
    
        <repositories>
            <repository>
                <id>sonatype-nexus-staging</id>
                <name>Sonatype Nexus Staging</name>
                <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
        </repositories>
    
        <properties>
            <java.version>1.8</java.version>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
            <spring-boot.version>2.2.6.RELEASE</spring-boot.version>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-lang3</artifactId>
                <version>3.8.1</version>
            </dependency>
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>fastjson</artifactId>
                <version>1.2.68.noneautotype</version>
            </dependency>
            <dependency>
                <groupId>com.google.code.gson</groupId>
                <artifactId>gson</artifactId>
                <version>2.8.6</version>
            </dependency>
            <!-- kms密钥服务相关依赖,非必须 -->
            <dependency>
                <groupId>com.aliyun</groupId>
                <artifactId>kms20160120</artifactId>
                <version>1.2.2</version>
            </dependency>
            <!-- sts相关依赖,非必须 -->
            <dependency>
                <groupId>com.aliyun</groupId>
                <artifactId>sts20150401</artifactId>
                <version>1.1.4</version>
            </dependency>
            <dependency>
                <groupId>com.aliyun</groupId>
                <artifactId>alibabacloud-mts20140618</artifactId>
                <version>3.0.0</version>
            </dependency>
             <dependency>
                <groupId>com.aliyun</groupId>
                <artifactId>tea-openapi</artifactId>
                <version>0.3.4</version>
              </dependency>
              <dependency>
                <groupId>com.aliyun</groupId>
                <artifactId>tea-console</artifactId>
                <version>0.0.1</version>
              </dependency>
              <dependency>
                <groupId>com.aliyun</groupId>
                <artifactId>tea-util</artifactId>
                <version>0.2.22</version>
              </dependency>
        </dependencies>
    
    </project>