This topic uses the Windows operating system and the IntelliJ IDEA software to describe how to install Elastic Desktop Service (EDS) Enterprise SDK for Java.
Prerequisites
The Java Development Kit (JDK) is installed. If not, refer to Install the JDK on Windows to install it.
IntelliJ IDEA is installed. If not, refer to Build a Java development environment on Windows to install it.
Procedure
Install by using sample code from OpenAPI Explorer
Open the DescribeOfficeSites document and click the Debug option in the upper-right corner of the page.
Log on to OpenAPI Portal by using your Alibaba Cloud account.
Configure the required parameters and click Initiate Call to obtain the response.
To access the sample code after debugging, go to the SDK Sample Code tab in the right panel, choose your preferred programming language, and then click Download Project.
NoteThe complete project includes the SDK details and a demo for API operation calls.
Open IntelliJ IDEA. In the top navigation bar, choose , open and decompress the sample project folder. Then, wait for Maven to automatically install relevant dependencies.
Before you make a call, make sure that an AccessKey pair is obtained. We recommend that you use the AccessKey pair of a Resource Access Management (RAM) user. For more information, see Create an AccessKey pair. After you obtain the AccessKey pair of the RAM user, you must configure the AccessKey pair in environment variables. For more information, see Configure environment variables in Linux, macOS, and Windows.
Double-click Sample.java and click the icon in the upper-right corner of the page.
View the execution result. In the log window, press
Ctrl+Fand search forstatusCode. If"statusCode":200, the call is successful.
Install in an existing project
Obtain EDS Enterprise SDK for Java.
Go to the SDK Center of EDS Enterprise and choose an installation method. In this example, Apache Maven is used.

Integrate the SDK into your application.
Open the Maven project created in IntelliJ IDEA, insert the
<dependencies></dependencies>tag pair into the pom.xml file, and then insert the Apache Maven dependencies obtained in the previous step into the tag pair.<dependencies> <dependency> <groupId>com.aliyun</groupId> <artifactId>alibabacloud-ecd20200930</artifactId> <version>4.0.21</version> </dependency> </dependencies>Download dependencies.
Right-click the project name and choose from the shortcut menu to download Maven dependencies.
Create a Java class.
Right-click the
src/main/javadirectory and select , enter the name Sample, and press Enter.
Initialize the cloud service client.
ImportantTo initialize the client, you must use an AccessKey pair for identity verification. Ensure you obtain the AccessKey pair beforehand. For more information about how to obtain an AccessKey pair, see Create an AccessKey pair.
After you obtain the AccessKey pair of a RAM user, you must configure the AccessKey pair in environment variables. For more information, see Configure environment variables in Linux, macOS, and Windows.
For information about endpoints, see Endpoints.
import com.aliyun.ecd20200930.Client; import com.aliyun.teaopenapi.models.Config; public class Sample { public static void main(String[] args) throws Exception { Config config = new Config() .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")) .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")); config.endpoint = "ecd.cn-shanghai.aliyuncs.com"; Client client = new Client(config); } }Call an API operation.
Before you call an API operation, you must read the corresponding API document. In Maven dependencies for a cloud service, the cloud service SDK includes a request class and a response class for each API operation. The request class specifies the parameters and their value types, while the response class defines the structure of the response. This design helps avoid spelling errors when you call the operation.
NoteNaming rule for request classes: API operation name + Request Example: DescribeOfficeSitesRequest.
Naming rule for response classes: API operation name + Response Example: DescribeOfficeSitesResponse.
import com.aliyun.ecd20200930.Client; import com.aliyun.ecd20200930.models.DescribeOfficeSitesRequest; import com.aliyun.ecd20200930.models.DescribeOfficeSitesResponse; import com.aliyun.teaopenapi.models.Config; public class Sample { public static void main(String[] args) throws Exception { Config config = new Config() .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")) .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")); config.endpoint = "ecd.cn-shanghai.aliyuncs.com"; Client client = new Client(config); DescribeOfficeSitesRequest describeOfficeSitesRequest = new DescribeOfficeSitesRequest() .setRegionId("cn-shanghai"); DescribeOfficeSitesResponse describeOfficeSitesResponse = client.describeOfficeSites(describeOfficeSitesRequest, runtime); } }Handle exceptions.
Alibaba Cloud SDKs manage exceptions uniformly.
TeaException: triggered by business-related errors. The following parameters can assist in troubleshooting the issue:
Message: the error message returned when an exception occurs. It includes the request ID.
Data: the detailed error information returned by the server for the exception.
FAQ
Question 1: What do I do if the "java.lang.NullPointerException: Cannot invoke "java.util.Map.get(Object)" because the return value of "com.aliyun.tea.TeaException.getData()" is null" error message is returned?
The issue may be caused by improperly configured Alibaba Cloud credentials, such as an invalid or missing AccessKey pair.
Negative example:
The code exposes the AccessKey pair by passing it directly to System.getenv() in plaintext, resulting in this error when the credentials aren't properly configured.
Config config = new Config()
// System.getenv() specifies that the AccessKey ID and AccessKey secret are obtained from environment variables.
// Required. Ensure the environment variable ALIBABA_CLOUD_ACCESS_KEY_ID is set in your runtime environment.
. setAccessKeyId(System.getenv("<YOUR_ACCESS_KEY_ID>")) // The AccessKey ID in plaintext.
// Required. Ensure the environment variable ALIBABA_CLOUD_ACCESS_KEY_SECRET is set in your runtime environment.
.setAccessKeySecret(System.getenv("<YOUR_ACCESS_KEY_SECRET>")); // The AccessKey secret in plaintext.Positive example:
In the code, set the AccessKey pair as environment variables, and then retrieve it by using System.getenv().
Config config = new Config()
// System.getenv() specifies that the AccessKey ID and AccessKey secret are obtained from environment variables.
// Required. Ensure the environment variable ALIBABA_CLOUD_ACCESS_KEY_ID is set in your runtime environment.
.setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
// Required. Ensure the environment variable ALIBABA_CLOUD_ACCESS_KEY_SECRET is set in your runtime environment.
.setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));Solutions:
Avoid hard-coding the AccessKey ID and AccessKey secret in your code, as it creates security risks.
System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID") and System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET") specify that the AccessKey ID and AccessKey secret are obtained from the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables.
Check whether the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables are configured.
On Linux or macOS, run the following commands on a terminal. On Windows, choose Start > Run or press Win+R, enter cmd in the dialog box that appears, click OK or press the Enter key, and then run the following commands in the command prompt window. If the valid AccessKey pair is returned, the configuration is successful. If no AccessKey pair is returned or an error is reported, configure the environment variables again. For more information, see Integrate with Alibaba Cloud SDK V2.0 for Python.
Windows
echo %ALIBABA_CLOUD_ACCESS_KEY_ID%
echo %ALIBABA_CLOUD_ACCESS_KEY_SECRET%Linux/macOS
echo $ALIBABA_CLOUD_ACCESS_KEY_ID
echo $ALIBABA_CLOUD_ACCESS_KEY_SECRETQuestion 3: What do I do if the "java: Error: release version X not supported" error mesage is returned?
Press theCtrl, Alt, Shift, and Skeys at the same time to open the Project Structure window. In the left-side navigation pane, click Modules. Select the same version as the JDK version that you use from the Language level drop-down list. For example, if you use JDK 8, select 8 - Lambdas, type annotations etc. Click Apply and then click OK.

Question 4: What do I do if the "java: Compilation failed: internal java compiler error" error message is returned?
In the menu bar of IntelliJ IDEA, choose File > Settings. In the left-side navigation pane, choose Build, Execution, Deployment > Compiler > Java Compiler. On the page that appears, select values from the Project bytecode version and Target bytecode version drop-down lists based on the JDK version that you use. For example, you can select 8 for the two parameters if you use JDK 8. Click Apply and then click OK.

Question 4: What do I do if the “No SLF4J providers were found” error message is reported?
The error "No SLF4J providers were found" typically occurs when SLF4J is used in the project, but no valid logging implementation library is detected. To resolve this issue, add the necessary dependencies to your project. For example, include log4j-slf4j-impl dependencies in the pom file.
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.17.0</version>
</dependency>