Jon*_*nas 20 java intellij-idea gradle 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'
}
Run Code Online (Sandbox Code Playgroud)
我的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<Void> fut) {
vertx.createHttpServer()
.requestHandler(r -> r.response().end("<h1>Hello</h1>"))
.listen(8081);
}
}
Run Code Online (Sandbox Code Playgroud)
我的IntelliJ运行配置如下,io.vertx.core.Starter主要类:

但是,当我使用我的运行配置运行它时,我收到以下错误消息:
Error: Could not find or load main class run
Run Code Online (Sandbox Code Playgroud)
VM选项(在运行配置中)run是否需要安装并添加到我的路径中?或者如何开始使用Vert.x-server开发?
小智 36
我正在使用vertx 3.2.1而且它正在抱怨io.vertx.core.Starter.它已被弃用了.所以,应该使用io.vertx.core.Launcher.
这是通过intellij启动并选择指定配置JSON文件的示例:
io.vertx.core.Launcher<up to you, or leave blank>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
Run Code Online (Sandbox Code Playgroud)
的logback:
-Dvertx.logger-delegate-factory-class-name=io.vertx.core.logging.SLF4JLogDelegateFactory -Dlogback.configurationFile=logback.xml
Run Code Online (Sandbox Code Playgroud)
Jar*_*red 14
只需将此添加到您的MyVerticle(或单独的类):
import io.vertx.core.Launcher;
...
public static void main(final String[] args) {
Launcher.executeCommand("run", MyVerticle.class.getName());
}
Run Code Online (Sandbox Code Playgroud)
然后只需Ctrl+Shift+F10运行它,IntelliJ将自动创建Run Configuration.
您可以简单地添加一个 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);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18792 次 |
| 最近记录: |