Quick Start
This topic explains how to install Java and use the Java SDK.
Prerequisites
Requirements
-
You have JDK 1.8 or later installed. Download JDK 1.8
-
You have IntelliJ IDEA installed. Download IntelliJ IDEA
-
You need an AccessKey to authenticate your API calls. It consists of an AccessKey ID and an AccessKey Secret. For instructions on how to create an AccessKey, see Create an AccessKey.
Verify the version
Open a terminal and run java -version to check your Java (JDK) version.
Run the sample code
Step 1: Download the full SDK project
-
Sign in to OpenAPI Explorer.
-
In the top navigation bar, click Select Cloud Product. In the panel that appears, select a cloud product.
-
Go to the product homepage. In the top navigation bar, click API Debugging to open a page with three panes.
-
In the left pane, select an API operation. In the middle pane, enter the required parameters. In the right pane, select the SDK Sample tab.
-
Set SDK Version to V2.0, and then select your preferred programming language.
-
Click Download Full Project.
-
To generate code for a generic call, select the Generate code in common mode checkbox. For more information, see Generic and typed calls.
Step 2: Configure environment variables
-
Open a command-line terminal. Replace
<ACCESS_KEY_ID>and<ACCESS_KEY_SECRET>in the following commands with your AccessKey ID and AccessKey Secret, and then run each command.export ALIBABA_CLOUD_ACCESS_KEY_ID=<ACCESS_KEY_ID> export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<ACCESS_KEY_SECRET> -
Restart your IDE to ensure it reads the environment variables.
NoteOn Linux, the preceding commands set a temporary environment variable that is valid only for the current terminal session. For example, you can package your application into a JAR file by running
mvn package, and then run the JAR file from the same terminal session by runningjava -jar <jarfilepath>.
Step 3: Run the code
-
Run the code in IntelliJ IDEA. Check the console log for the response body and the
requestId. -
If you call an API operation that creates an instance, the response also returns an instance ID. Use this instance ID to verify the result on the product console.