本文介绍阿里云Java SDK推荐的Maven安装方式。具体包含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的详细版本:

    以3.5.0版本SDK的核心库和2.5.2版本的媒体处理SDK为例:
    <dependency>
             <groupId>com.aliyun</groupId>
             <artifactId>aliyun-java-sdk-core</artifactId>
             <version>3.5.0</version>
       </dependency>
       <dependency>
             <groupId>com.aliyun</groupId>
             <artifactId>aliyun-java-sdk-mts</artifactId>
             <version>2.5.2</version>
       </dependency>
    另外有一个可选的json库依赖。在媒体处理的API中,很多参数都是json定义,java的json库有很多,可以选择熟悉的库,以1.2.46版本的 fastjson 为例:
    <dependency>
           <groupId>com.alibaba</groupId>
           <artifactId>fastjson</artifactId>
           <version>1.2.46</version>
       </dependency>
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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>mps-demo-project</groupId>
  <artifactId>mps-demo-project</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <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>
  <dependencies>
      <dependency>
          <groupId>com.aliyun</groupId>
          <artifactId>aliyun-java-sdk-core</artifactId>
          <version>3.5.0</version>
      </dependency>
      <dependency>
          <groupId>com.aliyun</groupId>
          <artifactId>aliyun-java-sdk-mts</artifactId>
          <version>2.5.2</version>
      </dependency>
      <dependency>
          <groupId>com.alibaba</groupId>
          <artifactId>fastjson</artifactId>
          <version>1.2.46</version>
      </dependency>
  </dependencies>
  <build>
      <finalName>${artifactId}-${version}</finalName>
      <plugins>
          <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-compiler-plugin</artifactId>
              <version>2.3.2</version>
              <configuration>
                  <source>1.6</source>
                  <target>1.6</target>
              </configuration>
          </plugin>
      </plugins>
  </build>
  </project>