The IoT Java SDK allows you to create Java applications to manage IoT Platform resources with ease. You can add the SDK as a Maven dependency to your project, or download the installation package to a local directory and install the SDK.

Install the IoT Java SDK

  1. Install a Java development environment.

    You can download a Java IDE from Java official website, and install the IDE by following the instructions.

  2. Install the IoT Java SDK.
    1. Visit Apache Maven official website to download a Maven installation package.
    2. Add a Maven dependency.
      Maven coordinates of the IoT Java SDK dependency
      <! -- -->
      Public libraries

Initialize the SDK

Note The following example uses the China (Shanghai) region and the corresponding endpoint. You must specify the region of your IoT Platform and the endpoint of your service to use the SDK.
String accessKey = "<your accessKey>";
String accessSecret = "<your accessSecret>";
DefaultProfile.addEndpoint("cn-shanghai", "cn-shanghai", "Iot", "");
IClientProfile profile = DefaultProfile.getProfile("cn-shanghai", accessKey, accessSecret);
DefaultAcsClient client = new DefaultAcsClient(profile); //Initialize the SDK

accessKeyId is the AccessKeyId of your account, and accessSecret is the AccessKeySecret paired with the AccessKeyId. You can go to AccessKey page in the console to create or view your AccessKey.

Initiate a call

The following example demonstrates how to call the Pub operation to publish messages to a topic.

PubRequest request = new PubRequest(); 
request.setMessageContent(Base64.encodeBase64String("hello world".getBytes())); 
request.setQos(0); //support QoS0 and QoS1 
   PubResponse response = client.getAcsResponse(request); 
catch (ServerException e) 
 catch (ClientException e)


Alibaba Cloud provides OpenAPI Explorer to simplify API usage. You can use OpenAPI Explorer to search for API operations, call API operations, and dynamically generate SDK sample code. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs. On the right side of the page, you can view the sample code of an SDK on the Example Code tab. On the Debugging Result tab, you can view the real request URL and response in the JSON format.