All Products
Search
Document Center

Content Moderation:Installation

Last Updated:Jul 31, 2023

This topic describes how to install Content Moderation SDK for Java. aliyun-java-sdk-green 3.6.6 is used as an example.

Prerequisites

Java 1.6 or later is installed.

Note

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

Install the SDK

To use aliyun-java-sdk-green in your Maven project, you need only to add relevant dependencies to the pom.xml file. For example, if you want to use aliyun-java-sdk-green 3.6.6, add the following content to <dependencies>:

<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>aliyun-java-sdk-core</artifactId>
    <version>4.1.1</version>
</dependency>
<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>aliyun-java-sdk-green</artifactId>
    <version>3.6.6</version>
</dependency>
<dependency>
    <groupId>com.alibaba.fastjson2</groupId>
    <artifactId>fastjson2</artifactId>
    <version>2.0.9</version>
</dependency>
<dependency>
    <groupId>com.aliyun.oss</groupId>
    <artifactId>aliyun-sdk-oss</artifactId>
    <version>2.8.3</version>
</dependency>

Part of the Java sample code is compiled based on Java dependencies to read files and convert strings. You can add the following content to <dependencies> as required:

<dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.4</version>
</dependency>
<dependency>
    <groupId>commons-codec</groupId>
    <artifactId>commons-codec</artifactId>
    <version>1.10</version>
</dependency>

If you want to submit a local or binary file for content moderation, download and import the Extension.Uploader utility class into your project.

Configure environment variables

In Alibaba Cloud SDK code, you can create a default access credential by defining ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables. When you call API operations of Alibaba Cloud services, the system directly accesses the credential, reads your AccessKey pair, and then automatically completes authentication. Before you use the SDK sample code, you must configure environment variables. For more information, see Configure credentials.