开发者社区> 问答> 正文

如何使用Java SDK?

如何使用Java SDK?

展开
收起
小天使爱美 2020-03-20 19:31:27 2317 0
3 条回答
写回答
取消 提交回答
  • 个人对建模比较关注

    pom中可以指定外部文件的。

    2020-03-25 17:30:46
    赞同 展开评论 打赏
  • 在idea中的module引入你的sdk即可

    2020-03-21 14:31:39
    赞同 展开评论 打赏
  • 概述 本文介绍如何使用ECI Java SDK以及阿里云核心库。

    准备 安装Java SDK

    您可以自行下载aliyun-java-sdk-eci;也可以使用Maven坐标来使用SDK(推荐使用)。

    Java SDK 的Maven地址:https://search.maven.org/search?q=a:aliyun-java-sdk-eci

    通过使用Maven坐标来使用SDK,只需在 Maven pom.xml 添加以下依赖项即可:

    com.aliyun aliyun-java-sdk-core true [4.3.2,5.0.0) com.google.code.gson gson 2.8.5 com.aliyun aliyun-java-sdk-eci 1.0.12 Demo示例 创建一个ECI实例

    import com.aliyuncs.DefaultAcsClient; import com.aliyuncs.IAcsClient; import com.aliyuncs.exceptions.ClientException; import com.aliyuncs.exceptions.ServerException; import com.aliyuncs.profile.DefaultProfile; import com.google.gson.Gson; import java.util.; import com.aliyuncs.eci.model.v20180808.;

    public class CreateContainerGroup {

    public static void main(String[] args) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-beijing", "<accessKeyId>", "<accessSecret>");
        IAcsClient client = new DefaultAcsClient(profile);
    
        CreateContainerGroupRequest request = new CreateContainerGroupRequest();
        request.setRegionId("cn-beijing");
        request.setSecurityGroupId("sg-2ze50xxve5raqetki8at");
        request.setVSwitchId("vsw-2ze462895gttskw2yc6wh");
        request.setContainerGroupName("test");
    
        List<CreateContainerGroupRequest.Container> containerList = new ArrayList<CreateContainerGroupRequest.Container>();
    
        CreateContainerGroupRequest.Container container1 = new CreateContainerGroupRequest.Container();
        container1.setImage("nginx");
        container1.setName("nginx");
        containerList.add(container1);
        request.setContainers(containerList);
    
        try {
            CreateContainerGroupResponse response = client.getAcsResponse(request);
            System.out.println(new Gson().toJson(response));
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            System.out.println("ErrCode:" + e.getErrCode());
            System.out.println("ErrMsg:" + e.getErrMsg());
            System.out.println("RequestId:" + e.getRequestId());
        }
    
    }
    

    } 返回数据

    {"containerGroupId":"eci-bp1h4oxf96kajk0kdfl1","requestId":"8E93976E-E73B-410F-B048-F6E8488E6D51"} 删除指定ECI实例 import com.aliyuncs.DefaultAcsClient; import com.aliyuncs.IAcsClient; import com.aliyuncs.exceptions.ClientException; import com.aliyuncs.exceptions.ServerException; import com.aliyuncs.profile.DefaultProfile; import com.google.gson.Gson; import java.util.; import com.aliyuncs.eci.model.v20180808.;

    public class DeleteContainerGroup {

    public static void main(String[] args) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-beijing", "<accessKeyId>", "<accessSecret>");
        IAcsClient client = new DefaultAcsClient(profile);
    
        DeleteContainerGroupRequest request = new DeleteContainerGroupRequest();
        request.setRegionId("cn-beijing");
        request.setContainerGroupId("eci-2ze4uq1ecwkm2nwf8odf");
    
        try {
            DeleteContainerGroupResponse response = client.getAcsResponse(request);
            System.out.println(new Gson().toJson(response));
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            System.out.println("ErrCode:" + e.getErrCode());
            System.out.println("ErrMsg:" + e.getErrMsg());
            System.out.println("RequestId:" + e.getRequestId());
        }
    
    }
    

    } 返回数据

    {"requestId":"30E08AC3-5BEE-4721-9E9C-BE0EC63AB494"}

    2020-03-20 19:31:55
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载