Overview
Java SDK consists of the public and product components of Alibaba Cloud Java SDK. The public component relies on aliyun-java-sdk-core, and the product component relies on aliyun-java-sdk-cr. For more information about each interface, see API overview.
Installation
You can use Maven repository to add SDK or download SDK, and add to project dependencies.
Maven dependency example
<!-- Check for the latest version of the SDK using the repository-->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-cr</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.0.1</version>
</dependency>
API call example
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.cr.model.v20160607.GetImageLayerRequest;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.HttpResponse;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
public class Sample {
public static void main(String[] args) {
try {
// Set a client
DefaultProfile.addEndpoint("cn-hanghzou", "cn-hangzhou", "cr", "cr.cn-hangzhou.aliyuncs.com");
IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", "AccessKeyId", "AccessKeySecret");
DefaultAcsClient client = new DefaultAcsClient(profile);
// Build a request
GetImageLayerRequest request = new GetImageLayerRequest();
// Set the parameters
request.setRepoName("repoName");
request.setRepoNamespace("repoNamespace");
request.setTag("tag");
// Make a request
HttpResponse response = client.doAction(request);
// Process the results
System.out.println(new String(response.getHttpContent()));
} catch (ClientException e) {
System.out.println("code: " + e.getErrCode());
System.out.println("message: " + e.getErrMsg());
}
}
}