使用Vert.x Maven插件快速创建项目的方法
本文介绍了使用Vert.xMaven插件快速创建项目的方法,分享给大家,具体如下:
文档地址:https://reactiverse.io/vertx-maven-plugin
已有项目添加该插件
在项目pom.xml目录,执行下面的命令即可添加:
mvnio.reactiverse:vertx-maven-plugin:1.0.17:setup
执行该命令后,在pom.xml中会增加下面的配置:
3.5.3 1.0.17 io.vertx vertx-stack-depchain ${vertx.version} pom import
还有下面的插件:
io.reactiverse vertx-maven-plugin ${vertx-maven-plugin.version} vmp initialize package true
自动引入的vert.x版本为3.5.3,你可以通过在mvn命令增加-DvertxVersion=3.4.0这个参数来指定需要的版本。
从头创建空项目
首先你必须创建一个目录,vert.x插件不会自动给你创建目录,只会创建目录内的src和pom.xml等文件。
创建一个目录,进入该目录内,在该目录内执行下面的命令:
mvnio.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是对应的依赖。
[ { "name":"Vert.xWeb", "labels":[ "web" ], "groupId":"io.vertx", "artifactId":"vertx-web" }, { "name":"Vert.xWebClient", "labels":[ "web-client" ], "groupId":"io.vertx", "artifactId":"vertx-web-client" }, { "name":"Vert.xMongoClient", "labels":[ "mongo" ], "groupId":"io.vertx", "artifactId":"vertx-mongo-client" }, { "name":"Vert.xKafkaClient", "labels":[ "kafka" ], "groupId":"io.vertx", "artifactId":"vertx-kafka-client" }, { "name":"Vert.xConsulClient", "labels":[ "consul" ], "groupId":"io.vertx", "artifactId":"vertx-consul-client" }, { "name":"Vert.xgRPC", "labels":[ "gRPC" ], "groupId":"io.vertx", "artifactId":"vertx-grpc" }, { "name":"Vert.x(async)JDBCClient", "labels":[ "jdbc" ], "groupId":"io.vertx", "artifactId":"vertx-jdbc-client" }, { "name":"Vert.xRedisClient", "labels":[ "redis" ], "groupId":"io.vertx", "artifactId":"vertx-redis-client" }, { "name":"Vert.xMailClient", "labels":[ "mail", "smtp" ], "groupId":"io.vertx", "artifactId":"vertx-mail-client" }, { "name":"Vert.xSTOMP", "labels":[ "stomp" ], "groupId":"io.vertx", "artifactId":"vertx-stomp" }, { "name":"Vert.xEventBusBridgeusingTCP", "labels":[ "tcp-bridge" ], "groupId":"io.vertx", "artifactId":"vertx-tcp-eventbus-bridge" }, { "name":"Vert.x-ApacheCamelbridge", "labels":[ "camel" ], "groupId":"io.vertx", "artifactId":"vertx-camel-bridge" }, { "name":"Vert.xBridgewithAMQP", "labels":[ "amqp" ], "groupId":"io.vertx", "artifactId":"vertx-amqp-bridge" }, { "name":"Vert.xClientforRabbitMQ", "labels":[ "rabbitmq" ], "groupId":"io.vertx", "artifactId":"vertx-rabbitmq-client" }, { "name":"Vert.xAuthenticationSupportusingJDBC", "labels":[ "jdbc-auth" ], "groupId":"io.vertx", "artifactId":"vertx-auth-jdbc" }, { "name":"Vert.xAuthenticationSupportusingJWT", "labels":[ "jwt-auth" ], "groupId":"io.vertx", "artifactId":"vertx-auth-jwt" }, { "name":"Vert.xAuthenticationSupportusingMongo", "labels":[ "mongo-auth" ], "groupId":"io.vertx", "artifactId":"vertx-auth-mongo" }, { "name":"Vert.xAuthenticationSupportusingShiro", "labels":[ "shiro-auth" ], "groupId":"io.vertx", "artifactId":"vertx-auth-shiro" }, { "name":"Vert.xAuthenticationSupportusingOAuth2", "labels":[ "oauth2", "oauth2-auth", "oauth" ], "groupId":"io.vertx", "artifactId":"vertx-auth-oauth2" }, { "name":"Vert.xsupportforRXJava", "labels":[ "rx", "rxjava" ], "groupId":"io.vertx", "artifactId":"vertx-rx-java" }, { "name":"Vert.xsupportforJavaScript(Nashorn)", "labels":[ "js", "javascript" ], "groupId":"io.vertx", "artifactId":"vertx-lang-js" }, { "name":"Vert.xsupportforKotlin", "labels":[ "kotlin", "vertx-kotlin" ], "groupId":"io.vertx", "artifactId":"vertx-lang-kotlin-compiler" }, { "name":"Vert.xsupportforRuby(JRuby)", "labels":[ "rb", "ruby", "jruby" ], "groupId":"io.vertx", "artifactId":"vertx-lang-ruby" }, { "name":"Vert.xsupportforApacheGroovy", "labels":[ "groovy" ], "groupId":"io.vertx", "artifactId":"vertx-lang-groovy" }, { "name":"Vert.xServiceDiscovery", "labels":[ "discovery", "service-discovery" ], "groupId":"io.vertx", "artifactId":"vertx-service-discovery" }, { "name":"Vert.xCircuitBreaker", "labels":[ "circuit-breaker", "circuit" ], "groupId":"io.vertx", "artifactId":"vertx-circuit-breaker" }, { "name":"Vert.xServiceDiscoveryforKubernetes", "labels":[ "discovery-kubernetes", "service-discovery-kubernetes" ], "groupId":"io.vertx", "artifactId":"vertx-service-discovery-bridge-kubernetes" }, { "name":"Vert.xServiceDiscoveryforConsul", "labels":[ "discovery-consul", "service-discovery-consul" ], "groupId":"io.vertx", "artifactId":"vertx-service-discovery-bridge-consul" }, { "name":"Vert.xMetricsusingDropwizard", "labels":[ "jmx", "dropwizard" ], "groupId":"io.vertx", "artifactId":"vertx-dropwizard-metrics" }, { "name":"Vert.xMetricsusingHawkular", "labels":[ "hawkular" ], "groupId":"io.vertx", "artifactId":"vertx-hawkular-metrics" }, { "name":"Vert.xShell", "labels":[ "shell" ], "groupId":"io.vertx", "artifactId":"vertx-shell" }, { "name":"Vert.xUnit", "labels":[ "test" ], "groupId":"io.vertx", "artifactId":"vertx-unit", "scope":"test" }, { "name":"Vert.xClusterManagerbasedonHazelcast", "labels":[ "hazelcast", "hazelcast-cluster-manager" ], "groupId":"io.vertx", "artifactId":"vertx-hazelcast" }, { "name":"Vert.xClusterManagerbasedonInfinipan", "labels":[ "infinispan", "infinispan-cluster-manager" ], "groupId":"io.vertx", "artifactId":"vertx-infinispan" }, { "name":"Vert.xClusterManagerbasedonZookeeper", "labels":[ "zookeeper-cluster-manager" ], "groupId":"io.vertx", "artifactId":"vertx-zookeeper" }, { "name":"Vert.xClusterManagerbasedonApacheIgnite", "labels":[ "ignite" ], "groupId":"io.vertx", "artifactId":"vertx-ignite" }, { "name":"Vert.xClusterManagerbasedonApacheZookeeper", "labels":[ "zookeeper" ], "groupId":"io.vertx", "artifactId":"vertx-zookeeper" }, { "name":"Vert.xWebTemplateEnginebasedonPebble", "labels":[ "pebble", "pebble-template", "pebble-template-engine" ], "groupId":"io.vertx", "artifactId":"vertx-web-templ-pebble", "classifier":"shaded" }, { "name":"Vert.xWebTemplateEnginebasedonApacheFreemarker", "labels":[ "freemarker", "freemarker-template", "freemarker-template-engine" ], "groupId":"io.vertx", "artifactId":"vertx-web-templ-freemarker", "classifier":"shaded" }, { "name":"Vert.xWebTemplateEnginebasedonThymeleaf", "labels":[ "thymeleaf", "thymeleaf-template", "thymeleaf-template-engine" ], "groupId":"io.vertx", "artifactId":"vertx-web-templ-thymeleaf", "classifier":"shaded" }, { "name":"Vert.xWebTemplateEnginebasedonHandlebars", "labels":[ "handlebars", "handlebars-template", "handlebars-template-engine" ], "groupId":"io.vertx", "artifactId":"vertx-web-templ-handlebars", "classifier":"shaded" }, { "name":"Vert.xWebTemplateEnginebasedonJade", "labels":[ "jade", "jade-template", "jade-template-engine" ], "groupId":"io.vertx", "artifactId":"vertx-web-templ-jade", "classifier":"shaded" }, { "name":"Vert.xWebTemplateEnginebasedonMVEL", "labels":[ "mvel", "mvel-template", "mvel-template-engine" ], "groupId":"io.vertx", "artifactId":"vertx-web-templ-mvel", "classifier":"shaded" }, { "name":"Vert.x(async)RPCserviceproxies", "labels":[ "service-proxies", "rpc-services" ], "groupId":"io.vertx", "artifactId":"vertx-service-proxy" }, { "name":"Vert.xServiceFactoryusingApacheMaven", "labels":[ "maven-service-factory" ], "groupId":"io.vertx", "artifactId":"vertx-maven-service-factory" }, { "name":"Vert.xServiceFactory", "labels":[ "service-factory" ], "groupId":"io.vertx", "artifactId":"vertx-service-factory" }, { "name":"Vert.xServiceFactoryusingHTTP", "labels":[ "http-service-factory" ], "groupId":"io.vertx", "artifactId":"vertx-http-service-factory" }, { "name":"Vert.xConfiguration", "labels":[ "config" ], "groupId":"io.vertx", "artifactId":"vertx-config" }, { "name":"Vert.xConfigurationwithKubernetesConfigMap", "labels":[ "config-kubernetes", "config-config-map", "config-configmap" ], "groupId":"io.vertx", "artifactId":"vertx-config-kubernetes-configmap" }, { "name":"Vert.xConfigurationwithaGitrepository", "labels":[ "config-git" ], "groupId":"io.vertx", "artifactId":"vertx-config-git" }, { "name":"Vert.xConfiguration-HOCONformat", "labels":[ "config-hocon" ], "groupId":"io.vertx", "artifactId":"vertx-config-hocon" }, { "name":"Vert.xConfiguration-Yamlformat", "labels":[ "config-yaml" ], "groupId":"io.vertx", "artifactId":"vertx-config-yaml" }, { "name":"Vert.xConfigurationwithaZookeeperbackend", "labels":[ "config-zookeeper" ], "groupId":"io.vertx", "artifactId":"vertx-config-zookeeper" }, { "name":"Vert.xConfigurationwithaRedisbackend", "labels":[ "config-redis" ], "groupId":"io.vertx", "artifactId":"vertx-config-redis" } ]
打包项目
集成了vert.x插件后,打包变的极其容易,只需要下面的命令:
mvncleanpackage
通过这种方式就会打出一个fatjar包,可以直接通过java-jarxxxx.jar运行的包。
其他命令
除了上面这些,还有vertx:run,vertx:debug,vertx:start,vertx:stop命令,这些命令可以在不打jar包的情况下运行或者关闭项目。
常见问题
通过插件方式运行时,你经常会遇到下面的问题:
[INFO]严重:java.net.BindException:Addressalreadyinuse:bind
这种情况是因为使用类似IDEAMaven插件中的命令直接双击运行时,你无法关闭这个应用。如果你使用的纯命令行,直接Ctrl+C就能关闭。
使用vertx:run在命令行运行时可以直接关闭。
使用vertx:start运行时,需要通过vertx:stop关闭。
万一遇上无法关闭的情况,在windows中,可以用下面方式解决。
在命令行中,输入下面的命令:
jps-m
这个命令会列出所有运行的jvm:
15248Jps-m
2384Launcherrunio.vertx.sample.MyFirstVerticleredeploy-termination-period=1000-Dvertx.id=5fd656fa-55a9-46b4-8d23-caa95f2e5032-redeploy
8208
11844Launcherrunio.vertx.sample.MyFirstVerticleredeploy-termination-period=1000-Dvertx.id=bec46d01-d441-4949-a2d9-f8ffbe85f965-redeploy
14200Launcherrunio.vertx.sample.MyFirstVerticle--redeploy=F:\Git\my-first-vertx-app\target\classes/**/*--redeploy-scan-period=1000redeploy-termi
nation-period=1000--launcher-class=io.vertx.core.Launcher
7580Launchercleancompilevertx:run
根据后面的信息找到你想关闭的jvm。输入下面的命令(假设关闭2384):
taskkill/f/pid2384
当相同端口的jvm关闭后,你就可以再次运行了。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。