如何从IntelliJ IDEA启动Vert.x服务器?
如何从IntelliJ IDEA内部启动简单的Vert.x服务器?
我的build.gradle
如下:
apply plugin: 'java' version = '3.0.0' repositories { mavenCentral() } dependencies { compile 'io.vertx:vertx-core:3.0.0' }
我的Vertx服务器, MyVertex.java
如下:
package com.example; import io.vertx.core.AbstractVerticle; import io.vertx.core.Future; public class MyVerticle extends AbstractVerticle { @Override public void start(Future fut) { vertx.createHttpServer() .requestHandler(r -> r.response().end("Hello
")) .listen(8081); } }
我的IntelliJ运行配置如下, io.vertx.core.Starter
作为主类:
但是,当我使用我的运行配置运行它时,我收到以下错误消息:
Error: Could not find or load main class run
VM选项(在运行配置中) run
我需要安装的东西并添加到我的路径中,或者我如何开始使用Vert.x-server开发?
我正在使用vertx 3.2.1,它抱怨io.vertx.core.Starter
。 它已被弃用了。 因此,应该使用io.vertx.core.Launcher
。
这是通过intellij启动并选择指定配置JSON文件的示例:
- 主类:
io.vertx.core.Launcher
- VM选项:
- 程序参数:
run com.app.verticle.MyVerticle -conf /path/to/my_config.json
使用日志记录框架时,它将添加到VM选项中,如下所示。
使用log4j或slf4j delgate的Log4j:
-Dvertx.logger-delegate-factory-class-name=io.vertx.core.logging.Log4jLogDelegateFactory -Dlog4j.configuration=log4j.xml -Dvertx.logger-delegate-factory-class-name=io.vertx.core.logging.SLF4JLogDelegateFactory -Dlog4j.configuration=log4j.xml
的logback:
-Dvertx.logger-delegate-factory-class-name=io.vertx.core.logging.SLF4JLogDelegateFactory -Dlogback.configurationFile=logback.xml
只需将其添加到MyVerticle
(或单独的类):
import io.vertx.core.Launcher; ... public static void main(final String[] args) { Launcher.executeCommand("run", MyVerticle.class.getName()); }
然后只需Ctrl+Shift+F10
即可运行它,IntelliJ将自动创建Run Configuration
。
啊,我的错误:
run com.example.MyVerticle
应该是Program arguments的值:而不是IntelliJ IDEA Run配置中的VM选项 。
你可以简单地添加一个main并使用deployVerticle(),然后在IntelliJ中你可以轻松地运行或调试它。 使用deployVerticle,您可以传递main / bootstrap Verticle的新实例,也可以传递yourMainVerticle.class
public class VertxVerticleMain { public static void main(String[] args) { Vertx vertx = Vertx.vertx(); vertx.deployVerticle(new MyVerticle()); //vertx.deployVerticle(MyVerticle.class); } }
您必须使用: org.vertx.java.platform.impl.cli.Starter
作为IntelliJ IDEA中的主类; 如果您正在使用参数和类似的东西,您可能想要使用类似: runmod
看看这个项目 。
对于Vert.x 3.0.0,您必须使用: io.vertx.core.Starter
作为您的主类,并run com.example.other.AnyVerticle
作为您的程序参数。