本文介紹了使用vert.x maven插件快速創建項目的方法,分享給大家,具體如下:
文檔地址: https://reactiverse.io/vertx-maven-plugin
已有項目添加該插件
在項目 pom.xml 目錄,執行下面的命令即可添加:
1
|
mvn io.reactiverse:vertx-maven-plugin: 1.0 . 17 :setup |
執行該命令后,在 pom.xml 中會增加下面的配置:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
<properties> <vertx.version> 3.5 . 3 </vertx.version> <vertx-maven-plugin.version> 1.0 . 17 </vertx-maven-plugin.version> </properties> <dependencymanagement> <dependencies> <dependency> <groupid>io.vertx</groupid> <artifactid>vertx-stack-depchain</artifactid> <version>${vertx.version}</version> <type>pom</type> <scope> import </scope> </dependency> </dependencies> </dependencymanagement> |
還有下面的插件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
<plugin> <groupid>io.reactiverse</groupid> <artifactid>vertx-maven-plugin</artifactid> <version>${vertx-maven-plugin.version}</version> <executions> <execution> <id>vmp</id> <goals> <goal>initialize</goal> <goal> package </goal> </goals> </execution> </executions> <configuration> <redeploy> true </redeploy> </configuration> </plugin> |
自動引入的 vert.x 版本為 3.5.3,你可以通過在 mvn 命令增加 -dvertxversion=3.4.0 這個參數來指定需要的版本。
從頭創建空項目
首先你 必須創建一個目錄 ,vert.x 插件不會自動給你創建目錄,只會創建目錄內的 src 和 pom.xml 等文件。
創建一個目錄,進入該目錄內,在該目錄內執行下面的命令:
1
2
3
4
5
6
7
|
mvn io.reactiverse:vertx-maven-plugin: 1.0 . 17 :setup ^ -dprojectgroupid=org.acme ^ -dprojectartifactid=acme-project ^ -dprojectversion= 1.0 -snapshot ^ -dverticle=org.acme.foo ^ -dverticle=io.vertx.sample.myfirstverticle ^ -ddependencies=web |
如果你使用的 linux 系統,將上面的 ^ 改為 \ 。
這里和上面相比增加了項目 gav 的配置。
通過 -dverticle=io.vertx.sample.myfirstverticle
,可以生成一個默認的 verticle 類。
通過 -ddependencies=web
可以指定你想加入的 vert.x 的依賴,這里寫的名字都是縮寫,具體對應關系看下面的介紹。
使用上面命令后,就創建了一個基礎 vert.x 項目,在開始學習 vert.x 的時候,通過這種方式可以更快的創建基礎項目。
-ddependencies 對照表
下面 json 中的 labels 就是縮寫名,groupid 和 artifactid 是對應的依賴。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
|
[ { "name" : "vert.x web" , "labels" : [ "web" ], "groupid" : "io.vertx" , "artifactid" : "vertx-web" }, { "name" : "vert.x web client" , "labels" : [ "web-client" ], "groupid" : "io.vertx" , "artifactid" : "vertx-web-client" }, { "name" : "vert.x mongo client" , "labels" : [ "mongo" ], "groupid" : "io.vertx" , "artifactid" : "vertx-mongo-client" }, { "name" : "vert.x kafka client" , "labels" : [ "kafka" ], "groupid" : "io.vertx" , "artifactid" : "vertx-kafka-client" }, { "name" : "vert.x consul client" , "labels" : [ "consul" ], "groupid" : "io.vertx" , "artifactid" : "vertx-consul-client" }, { "name" : "vert.x grpc" , "labels" : [ "grpc" ], "groupid" : "io.vertx" , "artifactid" : "vertx-grpc" }, { "name" : "vert.x (async) jdbc client" , "labels" : [ "jdbc" ], "groupid" : "io.vertx" , "artifactid" : "vertx-jdbc-client" }, { "name" : "vert.x redis client" , "labels" : [ "redis" ], "groupid" : "io.vertx" , "artifactid" : "vertx-redis-client" }, { "name" : "vert.x mail client" , "labels" : [ "mail" , "smtp" ], "groupid" : "io.vertx" , "artifactid" : "vertx-mail-client" }, { "name" : "vert.x stomp" , "labels" : [ "stomp" ], "groupid" : "io.vertx" , "artifactid" : "vertx-stomp" }, { "name" : "vert.x eventbus bridge using tcp" , "labels" : [ "tcp-bridge" ], "groupid" : "io.vertx" , "artifactid" : "vertx-tcp-eventbus-bridge" }, { "name" : "vert.x - apache camel bridge" , "labels" : [ "camel" ], "groupid" : "io.vertx" , "artifactid" : "vertx-camel-bridge" }, { "name" : "vert.x bridge with amqp" , "labels" : [ "amqp" ], "groupid" : "io.vertx" , "artifactid" : "vertx-amqp-bridge" }, { "name" : "vert.x client for rabbitmq" , "labels" : [ "rabbitmq" ], "groupid" : "io.vertx" , "artifactid" : "vertx-rabbitmq-client" }, { "name" : "vert.x authentication support using jdbc" , "labels" : [ "jdbc-auth" ], "groupid" : "io.vertx" , "artifactid" : "vertx-auth-jdbc" }, { "name" : "vert.x authentication support using jwt" , "labels" : [ "jwt-auth" ], "groupid" : "io.vertx" , "artifactid" : "vertx-auth-jwt" }, { "name" : "vert.x authentication support using mongo" , "labels" : [ "mongo-auth" ], "groupid" : "io.vertx" , "artifactid" : "vertx-auth-mongo" }, { "name" : "vert.x authentication support using shiro" , "labels" : [ "shiro-auth" ], "groupid" : "io.vertx" , "artifactid" : "vertx-auth-shiro" }, { "name" : "vert.x authentication support using oauth 2" , "labels" : [ "oauth2" , "oauth2-auth" , "oauth" ], "groupid" : "io.vertx" , "artifactid" : "vertx-auth-oauth2" }, { "name" : "vert.x support for rx java" , "labels" : [ "rx" , "rxjava" ], "groupid" : "io.vertx" , "artifactid" : "vertx-rx-java" }, { "name" : "vert.x support for javascript (nashorn)" , "labels" : [ "js" , "javascript" ], "groupid" : "io.vertx" , "artifactid" : "vertx-lang-js" }, { "name" : "vert.x support for kotlin" , "labels" : [ "kotlin" , "vertx-kotlin" ], "groupid" : "io.vertx" , "artifactid" : "vertx-lang-kotlin-compiler" }, { "name" : "vert.x support for ruby (jruby)" , "labels" : [ "rb" , "ruby" , "jruby" ], "groupid" : "io.vertx" , "artifactid" : "vertx-lang-ruby" }, { "name" : "vert.x support for apache groovy" , "labels" : [ "groovy" ], "groupid" : "io.vertx" , "artifactid" : "vertx-lang-groovy" }, { "name" : "vert.x service discovery" , "labels" : [ "discovery" , "service-discovery" ], "groupid" : "io.vertx" , "artifactid" : "vertx-service-discovery" }, { "name" : "vert.x circuit breaker" , "labels" : [ "circuit-breaker" , "circuit" ], "groupid" : "io.vertx" , "artifactid" : "vertx-circuit-breaker" }, { "name" : "vert.x service discovery for kubernetes" , "labels" : [ "discovery-kubernetes" , "service-discovery-kubernetes" ], "groupid" : "io.vertx" , "artifactid" : "vertx-service-discovery-bridge-kubernetes" }, { "name" : "vert.x service discovery for consul" , "labels" : [ "discovery-consul" , "service-discovery-consul" ], "groupid" : "io.vertx" , "artifactid" : "vertx-service-discovery-bridge-consul" }, { "name" : "vert.x metrics using dropwizard" , "labels" : [ "jmx" , "dropwizard" ], "groupid" : "io.vertx" , "artifactid" : "vertx-dropwizard-metrics" }, { "name" : "vert.x metrics using hawkular" , "labels" : [ "hawkular" ], "groupid" : "io.vertx" , "artifactid" : "vertx-hawkular-metrics" }, { "name" : "vert.x shell" , "labels" : [ "shell" ], "groupid" : "io.vertx" , "artifactid" : "vertx-shell" }, { "name" : "vert.x unit" , "labels" : [ "test" ], "groupid" : "io.vertx" , "artifactid" : "vertx-unit" , "scope" : "test" }, { "name" : "vert.x cluster manager based on hazelcast" , "labels" : [ "hazelcast" , "hazelcast-cluster-manager" ], "groupid" : "io.vertx" , "artifactid" : "vertx-hazelcast" }, { "name" : "vert.x cluster manager based on infinipan" , "labels" : [ "infinispan" , "infinispan-cluster-manager" ], "groupid" : "io.vertx" , "artifactid" : "vertx-infinispan" }, { "name" : "vert.x cluster manager based on zookeeper" , "labels" : [ "zookeeper-cluster-manager" ], "groupid" : "io.vertx" , "artifactid" : "vertx-zookeeper" }, { "name" : "vert.x cluster manager based on apache ignite" , "labels" : [ "ignite" ], "groupid" : "io.vertx" , "artifactid" : "vertx-ignite" }, { "name" : "vert.x cluster manager based on apache zookeeper" , "labels" : [ "zookeeper" ], "groupid" : "io.vertx" , "artifactid" : "vertx-zookeeper" }, { "name" : "vert.x web template engine based on pebble" , "labels" : [ "pebble" , "pebble-template" , "pebble-template-engine" ], "groupid" : "io.vertx" , "artifactid" : "vertx-web-templ-pebble" , "classifier" : "shaded" }, { "name" : "vert.x web template engine based on apache freemarker" , "labels" : [ "freemarker" , "freemarker-template" , "freemarker-template-engine" ], "groupid" : "io.vertx" , "artifactid" : "vertx-web-templ-freemarker" , "classifier" : "shaded" }, { "name" : "vert.x web template engine based on thymeleaf" , "labels" : [ "thymeleaf" , "thymeleaf-template" , "thymeleaf-template-engine" ], "groupid" : "io.vertx" , "artifactid" : "vertx-web-templ-thymeleaf" , "classifier" : "shaded" }, { "name" : "vert.x web template engine based on handlebars" , "labels" : [ "handlebars" , "handlebars-template" , "handlebars-template-engine" ], "groupid" : "io.vertx" , "artifactid" : "vertx-web-templ-handlebars" , "classifier" : "shaded" }, { "name" : "vert.x web template engine based on jade" , "labels" : [ "jade" , "jade-template" , "jade-template-engine" ], "groupid" : "io.vertx" , "artifactid" : "vertx-web-templ-jade" , "classifier" : "shaded" }, { "name" : "vert.x web template engine based on mvel" , "labels" : [ "mvel" , "mvel-template" , "mvel-template-engine" ], "groupid" : "io.vertx" , "artifactid" : "vertx-web-templ-mvel" , "classifier" : "shaded" }, { "name" : "vert.x (async) rpc service proxies" , "labels" : [ "service-proxies" , "rpc-services" ], "groupid" : "io.vertx" , "artifactid" : "vertx-service-proxy" }, { "name" : "vert.x service factory using apache maven" , "labels" : [ "maven-service-factory" ], "groupid" : "io.vertx" , "artifactid" : "vertx-maven-service-factory" }, { "name" : "vert.x service factory" , "labels" : [ "service-factory" ], "groupid" : "io.vertx" , "artifactid" : "vertx-service-factory" }, { "name" : "vert.x service factory using http" , "labels" : [ "http-service-factory" ], "groupid" : "io.vertx" , "artifactid" : "vertx-http-service-factory" }, { "name" : "vert.x configuration" , "labels" : [ "config" ], "groupid" : "io.vertx" , "artifactid" : "vertx-config" }, { "name" : "vert.x configuration with kubernetes configmap" , "labels" : [ "config-kubernetes" , "config-config-map" , "config-configmap" ], "groupid" : "io.vertx" , "artifactid" : "vertx-config-kubernetes-configmap" }, { "name" : "vert.x configuration with a git repository" , "labels" : [ "config-git" ], "groupid" : "io.vertx" , "artifactid" : "vertx-config-git" }, { "name" : "vert.x configuration - hocon format" , "labels" : [ "config-hocon" ], "groupid" : "io.vertx" , "artifactid" : "vertx-config-hocon" }, { "name" : "vert.x configuration - yaml format" , "labels" : [ "config-yaml" ], "groupid" : "io.vertx" , "artifactid" : "vertx-config-yaml" }, { "name" : "vert.x configuration with a zookeeper backend" , "labels" : [ "config-zookeeper" ], "groupid" : "io.vertx" , "artifactid" : "vertx-config-zookeeper" }, { "name" : "vert.x configuration with a redis backend" , "labels" : [ "config-redis" ], "groupid" : "io.vertx" , "artifactid" : "vertx-config-redis" } ] |
打包項目
集成了 vert.x 插件后,打包變的極其容易,只需要下面的命令:
1
|
mvn clean package |
通過這種方式就會打出一個 fat jar 包,可以直接通過 java -jar xxxx.jar 運行的包。
其他命令
除了上面這些,還有 vertx:run, vertx:debug, vertx:start, vertx:stop 命令,這些命令可以在不打 jar 包的情況下運行或者關閉項目。
常見問題
通過插件方式運行時,你經常會遇到下面的問題:
[info] 嚴重: java.net.bindexception: address already in use: bind
這種情況是因為使用類似 idea maven 插件中的命令直接雙擊運行時,你無法關閉這個應用。如果你使用的純命令行,直接 ctrl+c 就能關閉。
使用 vertx:run
在命令行運行時可以直接關閉。
使用 vertx:start
運行時,需要通過 vertx:stop
關閉。
萬一遇上無法關閉的情況,在 windows 中,可以用下面方式解決。
在命令行中,輸入下面的命令:
1
|
jps -m |
這個命令會列出所有運行的 jvm:
15248 jps -m
2384 launcher run io.vertx.sample.myfirstverticle redeploy-termination-period=1000 -dvertx.id=5fd656fa-55a9-46b4-8d23-caa95f2e5032-redeploy
8208
11844 launcher run io.vertx.sample.myfirstverticle redeploy-termination-period=1000 -dvertx.id=bec46d01-d441-4949-a2d9-f8ffbe85f965-redeploy
14200 launcher run io.vertx.sample.myfirstverticle --redeploy=f:\git\my-first-vertx-app\target\classes/**/* --redeploy-scan-period=1000 redeploy-termi
nation-period=1000 --launcher-class=io.vertx.core.launcher
7580 launcher clean compile vertx:run
根據后面的信息找到你想關閉的 jvm。輸入下面的命令(假設關閉 2384):
1
|
taskkill /f /pid 2384 |
當相同端口的 jvm 關閉后,你就可以再次運行了。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:https://blog.csdn.net/isea533/article/details/82655699