Install SDK for Java


Before you install and use Zenlayer Cloud SDK for Java, make sure that the following requirements are met:

  • The Java environment is installed. Java Development Kit (JDK) version 1.7 or later is used.

  • A Zenlayer Cloud account is created and an Access Key ID and an Access Key Password are created. See Generate an API Access Key for more details.

  • Obtain the service domain name. Currently the service domain name requested by Zenlayer Cloud API is

Install SDK

If you use Maven to manage Java projects, you can add Maven dependencies to the pom.xml file to install Zenlayer Cloud SDK for Java. In the Maven repository, you can view the Maven dependencies of Zenlayer Cloud services.

Add the following Maven dependency to install the core library of Zenlayer Cloud SDK for Java.

    <!-- Go to to check all new versions. The latest version: -->


The version that is used in the preceding dependency is a sample version. For information about the latest version of the core library, visit the Maven repository.

Method 2: Import the JAR package to your project

  1. Go to Github to download Java file.

  2. Unzip the source code file ( to a suitable location for your project.

  3. Put the decompressed JAR file in the path where Java can open it.

  4. Refer to the following Example.


Take CreateInstances as an example, you need to fill in the following parameters in the sample code according to your actual situation.

import com.zenlayercloud.bmc20221120.BmcClient;
import com.zenlayercloud.bmc20221120.models.request.CreateInstancesRequest;
import com.zenlayercloud.bmc20221120.models.response.CreateInstancesResponse;
import com.zenlayercloud.common.Credential;
import com.zenlayercloud.common.ZenlayerSdkException;

public class Example {

    public static void main(String[] args) {
        // 1. Initialize client
        Credential credential = new Credential("<AccessKey>", "<AccessSecret>");
        BmcClient client = new BmcClient(credential);
        // 2. Set API request parameters
        CreateInstancesRequest createInstancesRequest = new CreateInstancesRequest();
        createInstancesRequest.instanceChargeType = "PREPAID";
        createInstancesRequest.internetChargeType = "ByBandwidth";
        createInstancesRequest.zoneId = "SEL-A";
        createInstancesRequest.instanceTypeId = "M8C";

        try {
            // 3. Make an API request and get the response result
            CreateInstancesResponse instances = client.createInstances(createInstancesRequest);

        } catch (ZenlayerSdkException e) {
            // 4. Handle errors in response

Last updated