本文介绍了使用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 对照表
源码: dependencies.json
下面 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
查看更多关于使用Vert.x Maven插件快速创建项目的方法的详细内容...