This topic describes how to install Alibaba Cloud SDK for Java by using Maven.
Preparations
We recommend that you use Java 8 or later.
Procedure
The installation procedure consists of two steps: Add the Maven repository of Alibaba Cloud SDK for Java to the pom.xml file and add ApsaraVideo Media Processing (MPS) dependencies.
- Add the Maven repository.
<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>
- Add dependencies. The following sample code shows the dependencies on the core library version 4.6.0 of Alibaba Cloud SDK for Java and MPS SDK for Java 3.3.45. References:
<dependency> <groupId>com.aliyun</groupId> <artifactId>aliyun-java-sdk-core</artifactId> <version>4.6.0</version> </dependency> <dependency> <groupId>com.aliyun</groupId> <artifactId>aliyun-java-sdk-mts</artifactId> <version>3.3.45</version> </dependency>
In addition to the preceding libraries, you can also add JSON library dependencies. Many parameters in MPS API operations are in the JSON format. Therefore, you can select available libraries from the JSON libraries for Java. In this example, JSON library 1.2.68.noneautotype is used. The following sample code provides an example of the content of the pom.xml file:<?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> <!-- Optional. Add the Key Management Service (KMS) dependency. --> <dependency> <groupId>com.aliyun</groupId> <artifactId>aliyun-java-sdk-kms</artifactId> <version>2.10.1</version> </dependency> <!-- Optional. Add the Security Token Service (STS) dependency. --> <dependency> <groupId>com.aliyun</groupId> <artifactId>aliyun-java-sdk-sts</artifactId> <version>3.0.1</version> </dependency> <dependency> <groupId>com.aliyun</groupId> <artifactId>aliyun-java-sdk-core</artifactId> <version>4.6.0</version> </dependency> <dependency> <groupId>com.aliyun</groupId> <artifactId>aliyun-java-sdk-mts</artifactId> <version>3.3.45</version> </dependency> </dependencies> </project>