This topic describes how to use the SMC Java SDK to call the StartReplicationJob operation to start a migration task.

Background information

You can call the StartReplicationJob operation to start a migration task. For more information, see StartReplicationJob.

Note This API operation can only be used to start migration tasks that are in the Ready, Stopped, or InError state.

Sample code

The following code can be used to start a migration task:

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.aliyuncs.smc.model.v20190601.StartReplicationJobRequest;
import com.aliyuncs.smc.model.v20190601.StartReplicationJobResponse;

public class StartReplicationJob {
    public static void main(String[] args) {
        // Initialize the AcsClient instance, and set the region ID and your AccessKey pair.
        DefaultProfile profile = DefaultProfile.getProfile("<region-Id>", "<accessKeyId>", "<accessSecret>");
        IAcsClient client = new DefaultAcsClient(profile);

        // Create an API request and configure its parameters.
        StartReplicationJobRequest request = new StartReplicationJobRequest();
        // The ID of the migration task.

        // Send the request to obtain the return value or handle the exception.
        try {
            StartReplicationJobResponse response = client.getAcsResponse(request);
            System.out.println(new Gson().toJson(response));
        } catch (ServerException e) {
        } catch (ClientException e) {