Java SDK包含阿里云Java SDK公共部分和产品部分,公共部分依赖aliyun-java-sdk-core,产品部分依赖aliyun-java-sdk-cr。
安装
您可以使用Maven仓库引入SDK或下载SDK后添加到项目依赖中。
Maven依赖示例
<!-- 请通过仓库查询SDK最新版本号-->
<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调用示例
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 {
// 设置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);
// 构造请求
GetImageLayerRequest request = new GetImageLayerRequest();
// 设置参数
request.setRepoName("repoName");
request.setRepoNamespace("repoNamespace");
request.setTag("tag");
// 发起请求
HttpResponse response = client.doAction(request);
// 处理结果
System.out.println(new String(response.getHttpContent()));
} catch (ClientException e) {
System.out.println("code: " + e.getErrCode());
System.out.println("message: " + e.getErrMsg());
}
}
}
文档内容是否对您有帮助?