11# Volcengine SDK for Java
22
33## Table of Contents
4+
45* Requirements
56* Usage
67* API Dosc
78* Note
89
910### Requirements ###
11+
1012运行 SDK需要jdk ** Java 1.7+** . 你可以下载最新的版本: http://developers.sun.com/downloads/ .
1113如果 SDK版本 高于或者等于 ** Java 9** 请依赖javax.annotation-api
1214由于在高于或者等于 ** Java 9** 中 javax.annotation-api 被移除
1315
1416请在使用中引用
17+
1518``` xml
19+
1620<dependency >
17- <groupId >javax.annotation</groupId >
18- <artifactId >javax.annotation-api</artifactId >
19- <version >1.3.2</version >
21+ <groupId >javax.annotation</groupId >
22+ <artifactId >javax.annotation-api</artifactId >
23+ <version >1.3.2</version >
2024</dependency >
2125```
2226
2327### Usage ###
28+
2429* Getting Started
2530* Example
2631
2732#### Getting Started ####
2833
29- ##### 工程使用sdk #####
34+ ##### 安装说明 #####
3035
3136建议使用Maven构建自己的项目,添加需要的相应模块的依赖,示例如下:
3237
3338##### Init maven setting.xml #####
39+
3440如果您使用的版本大于0.1.27 可以不进行设置 直接使用中央仓库进行依赖
3541
3642如果您使用的版本小于或者等于0.1.27
3743需要使用字节跳动的maven仓库来完成依赖,请先到maven安装目录的conf/setting.xml
3844在<mirrors />标签中增加
3945
4046``` xml
47+
4148<mirror >
42- <id >bytedanceMaven</id >
43- <mirrorOf >my-repo-id</mirrorOf >
44- <name >字节跳动maven仓库</name >
45- <url >https://artifact.bytedance.com/repository/releases/</url >
49+ <id >bytedanceMaven</id >
50+ <mirrorOf >my-repo-id</mirrorOf >
51+ <name >字节跳动maven仓库</name >
52+ <url >https://artifact.bytedance.com/repository/releases/</url >
4653</mirror >
4754```
4855
4956##### Importing the pom #####
5057
5158``` xml
59+
5260<dependencyManagement >
53- <dependencies >
54- <dependency >
55- <groupId >com.volcengine</groupId >
56- <artifactId >volcengine-java-sdk-bom</artifactId >
57- <version >0.2.4</version >
58- <type >pom</type >
59- <scope >import</scope >
60- </dependency >
61- </dependencies >
61+ <dependencies >
62+ <dependency >
63+ <groupId >com.volcengine</groupId >
64+ <artifactId >volcengine-java-sdk-bom</artifactId >
65+ <version >0.2.4</version >
66+ <type >pom</type >
67+ <scope >import</scope >
68+ </dependency >
69+ </dependencies >
6270</dependencyManagement >
6371```
6472
65-
6673##### Using the SDK Maven modules #####
6774
6875``` xml
76+
6977<dependencies >
70- <dependency >
71- <groupId >com.volcengine</groupId >
72- <artifactId >volcengine-java-sdk-vpc</artifactId >
73- <version >0.2.4</version >
74- </dependency >
75- <dependency >
76- <groupId >com.volcengine</groupId >
77- <artifactId >volcengine-java-sdk-ecs</artifactId >
78- <version >0.2.4</version >
79- </dependency >
78+ <dependency >
79+ <groupId >com.volcengine</groupId >
80+ <artifactId >volcengine-java-sdk-vpc</artifactId >
81+ <version >0.2.4</version >
82+ </dependency >
83+ <dependency >
84+ <groupId >com.volcengine</groupId >
85+ <artifactId >volcengine-java-sdk-ecs</artifactId >
86+ <version >0.2.4</version >
87+ </dependency >
8088</dependencies >
8189```
8290
8391##### Credentials 配置 #####
8492
8593** 通过环境变量导入** :
94+
8695```
8796export VOLCENGINE_ACCESS_KEY=your ak
8897export VOLCENGINE_SECRET_KEY=your sk
@@ -93,12 +102,34 @@ export VOLCENGINE_SESSION_TOKEN=token
93102** 代码方式引入** :
94103
95104``` java
96- Credentials credentials = Credentials . getCredentials(ak,sk);
105+ Credentials credentials = Credentials . getCredentials(ak, sk);
97106// 如果使用token
98- Credentials credentials = Credentials . getCredentials(ak,sk, token);
107+ Credentials credentials = Credentials . getCredentials(ak, sk, token);
99108```
100109
101- #### Example ####
110+ ##### Endpoint 设置 #####
111+
112+ 如果您要自定义SDK的Endpoint,可以按照以下示例代码设置:
113+
114+ ``` java
115+ ApiClient apiClient = new ApiClient ()
116+ .setCredentials(Credentials . getCredentials(ak, sk))
117+ .setRegion(region). setEndpoint(" ecs.cn-beijing-autodriving.volcengineapi.com" );
118+ ```
119+
120+ 火山引擎标准的Endpoint规则说明:
121+
122+ | Regional 服务 | Global 服务 |
123+ | ----------------------------------------------------------------------------------------------------------------------------------------| ------------------------------------------------------------------------------------|
124+ | ` {service}.{region}.volcengineapi.com ` <br > 例如:云服务ecs在cn-beijing-autodriving Region域名为: ` ecs.cn-beijing-autodriving.volcengineapi.com ` | ` {service}.volcengineapi.com ` <br > 例如:访问控制iam为Global服务,域名为:` iam.volcengineapi.com ` |
125+
126+ 注:
127+
128+ - Service中存在_符号时,Endpoint时需转为-符号。存在大写字母时需转成小写。
129+ - 并非所有云产品和Region都支持标准域名,具体请前往您所使用的产品-API参考中查看。
130+
131+ #### SDK 示例 ####
132+
102133``` java
103134import com.volcengine.ApiClient ;
104135import com.volcengine.ApiException ;
@@ -111,26 +142,26 @@ import java.util.ArrayList;
111142import java.util.List ;
112143
113144public class TestVpc {
114- public static void main (String [] args )throws Exception {
115- String ak = " your ak" ;
116- String sk = " your sk" ;
117- String region = " cn-beijing" ;
118-
119- ApiClient apiClient = new ApiClient ()
120- .setCredentials(Credentials . getCredentials(ak,sk))
121- .setRegion(region);
122- VpcApi vpcApi = new VpcApi (apiClient);
123- DescribeVpcsRequest request = new DescribeVpcsRequest ();
124- List<String > list = new ArrayList<> ();
125- list. add(" vpc-13fpdgwk7rxfk3n6nu44wisg7" );
126- request. setVpcIds(list);
127- try {
128- DescribeVpcsResponse response = vpcApi. describeVpcs(request);
129- System . out. println(response);
130- } catch (ApiException e) {
131- System . out. println(e. getResponseBody());
145+ public static void main (String [] args ) throws Exception {
146+ String ak = " your ak" ;
147+ String sk = " your sk" ;
148+ String region = " cn-beijing" ;
149+
150+ ApiClient apiClient = new ApiClient ()
151+ .setCredentials(Credentials . getCredentials(ak, sk))
152+ .setRegion(region);
153+ VpcApi vpcApi = new VpcApi (apiClient);
154+ DescribeVpcsRequest request = new DescribeVpcsRequest ();
155+ List<String > list = new ArrayList<> ();
156+ list. add(" vpc-13fpdgwk7rxfk3n6nu44wisg7" );
157+ request. setVpcIds(list);
158+ try {
159+ DescribeVpcsResponse response = vpcApi. describeVpcs(request);
160+ System . out. println(response);
161+ } catch (ApiException e) {
162+ System . out. println(e. getResponseBody());
163+ }
132164 }
133- }
134165}
135166
136167```
0 commit comments