Container Registry SDK for Java includes Alibaba Cloud SDK for Java, which is the common part, and the Container Registry part. The common part depends on aliyun-java-sdk-core. The Container Registry part depends on aliyun-java-sdk-cr.
Installation
After you download the SDK, you can create a Maven project in your Maven repository and add Maven dependencies.
Sample code used to add Maven dependencies
<! -- Query the latest version number of the SDK from the repository.-->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-cr</artifactId>
<version>4.1.5</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.6.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 {
// Configure the 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);
// Construct a request.
GetImageLayerRequest request = new GetImageLayerRequest();
// Set request parameters.
request.setRepoName("repoName");
request.setRepoNamespace("repoNamespace");
request.setTag("tag");
// Initiate the request.
HttpResponse response = client.doAction(request);
// Process the response.
System.out.println(new String(response.getHttpContent()));
} catch (ClientException e) {
System.out.println("code: " + e.getErrCode());
System.out.println("message: " + e.getErrMsg());
}
}
}