如何开始绿色。x服务器来自IntelliJ IDEA?

时间:2022-10-04 18:06:32

How do I start a simple Vert.x server from inside IntelliJ IDEA?

我如何开始一个简单的心灵。x服务器来自IntelliJ IDEA?

My build.gradle is as below:

我的建立。gradle是如下:

apply plugin: 'java'

version = '3.0.0'

repositories {
    mavenCentral()
}

dependencies {
    compile 'io.vertx:vertx-core:3.0.0'
}

My Vertx-server, MyVertex.java is as below:

我的Vertx-server 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);
    }
}

And my IntelliJ run configuration is as below, with io.vertx.core.Starteras main class: 如何开始绿色。x服务器来自IntelliJ IDEA?

我的IntelliJ运行配置如下所示,用的是io.vertx.core。Starteras主要类:

But when I run it with my run configuration I get this error message:

但是当我使用我的run配置运行它时,我得到了这个错误信息:

Error: Could not find or load main class run

Is the VM option (in Run configuration) run something I need to install and add to my path or how do I get started with Vert.x-server development?

是VM选项(在运行配置中)运行我需要安装并添加到我的路径或如何开始使用Vert的东西。x服务器开发?

5 个解决方案

#1


22  

I'm using vertx 3.2.1 and it's complaining about io.vertx.core.Starter. It's deprecated now. So, one should use io.vertx.core.Launcher.

我使用的是vertx3.2.1,它抱怨的是io.vertx.core.Starter。现在的弃用。因此,应该使用io.vertx.core.Launcher。

This is an example of launching via intellij with the option of specifying a config JSON file:

这是一个通过intellij启动的例子,它可以指定一个配置JSON文件:

  • Main Class: io.vertx.core.Launcher
  • 主要课程:io.vertx.core.Launcher
  • VM Options: <up to you, or leave blank>
  • VM选项:
  • Program Arguments: run com.app.verticle.MyVerticle -conf /path/to/my_config.json
  • 程序参数:运行com.app.verticle。/ / my_config.json MyVerticle conf /路径

When using a logging framework it will be added in VM Options as below.

当使用日志框架时,它将被添加到VM选项中,如下所示。

Log4j with either log4j or slf4j delgate:

Log4j和Log4j或slf4j delgate:

-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:

Logback:

-Dvertx.logger-delegate-factory-class-name=io.vertx.core.logging.SLF4JLogDelegateFactory -Dlogback.configurationFile=logback.xml

#2


7  

Simply add this to your MyVerticle (or a separate class):

只需将此添加到您的MyVerticle(或单独的类):

import io.vertx.core.Launcher;
...
public static void main(final String[] args) {
    Launcher.executeCommand("run", MyVerticle.class.getName());
}

Then simply Ctrl+Shift+F10 to run it and IntelliJ will automatically create the Run Configuration.

然后按Ctrl+Shift+F10运行它,IntelliJ会自动创建运行配置。

#3


5  

Ah, my mistake:

啊,我的错误:

run com.example.MyVerticle should be the value of Program arguments: and not as VM options in the IntelliJ IDEA Run configuration.

com . example。运行MyVerticle应该是程序参数的值:而不是IntelliJ IDEA Run配置中的VM选项。

#4


2  

You can simply add a main and use deployVerticle() and then from there in IntelliJ you can Run or Debug it easily. With deployVerticle, you can pass a new instance of your main/bootstrap verticle or you can pass yourMainVerticle.class

您可以简单地添加一个main并使用deployVerticle(),然后在IntelliJ中,您可以轻松地运行或调试它。使用deployVerticle,您可以传递主/引导程序verticle的一个新实例,也可以传递main .class

public class VertxVerticleMain {

    public static void main(String[] args) {
        Vertx vertx = Vertx.vertx();

        vertx.deployVerticle(new MyVerticle());
       //vertx.deployVerticle(MyVerticle.class);

    }
}

#5


1  

You have to use this: org.vertx.java.platform.impl.cli.Starter as your Main Class in IntelliJ IDEA; and if you are using arguments and things like that you might want to use something like: runmod <groupId>~<artifactId>~<version> [-conf src/main/resources/your_config.json -cp]

您必须使用这个:org.vertx.java.platform.impl.cli。作为你在IntelliJ IDEA的主类;如果您正在使用参数或类似的东西,您可能希望使用以下内容:runmod ~ ~ [-conf src/main/resources/your_config]。json - cp)

Have a look at this project.

看看这个项目。

For Vert.x 3.0.0 you have to use this: io.vertx.core.Starter as your Main Class and run com.example.other.AnyVerticle as your Program arguments.

为绿色。x 3。0你必须使用这个:io.vertx。core。开始你的主课程,运行com.example.other。任何verticle作为你的程序参数。

#1


22  

I'm using vertx 3.2.1 and it's complaining about io.vertx.core.Starter. It's deprecated now. So, one should use io.vertx.core.Launcher.

我使用的是vertx3.2.1,它抱怨的是io.vertx.core.Starter。现在的弃用。因此,应该使用io.vertx.core.Launcher。

This is an example of launching via intellij with the option of specifying a config JSON file:

这是一个通过intellij启动的例子,它可以指定一个配置JSON文件:

  • Main Class: io.vertx.core.Launcher
  • 主要课程:io.vertx.core.Launcher
  • VM Options: <up to you, or leave blank>
  • VM选项:
  • Program Arguments: run com.app.verticle.MyVerticle -conf /path/to/my_config.json
  • 程序参数:运行com.app.verticle。/ / my_config.json MyVerticle conf /路径

When using a logging framework it will be added in VM Options as below.

当使用日志框架时,它将被添加到VM选项中,如下所示。

Log4j with either log4j or slf4j delgate:

Log4j和Log4j或slf4j delgate:

-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:

Logback:

-Dvertx.logger-delegate-factory-class-name=io.vertx.core.logging.SLF4JLogDelegateFactory -Dlogback.configurationFile=logback.xml

#2


7  

Simply add this to your MyVerticle (or a separate class):

只需将此添加到您的MyVerticle(或单独的类):

import io.vertx.core.Launcher;
...
public static void main(final String[] args) {
    Launcher.executeCommand("run", MyVerticle.class.getName());
}

Then simply Ctrl+Shift+F10 to run it and IntelliJ will automatically create the Run Configuration.

然后按Ctrl+Shift+F10运行它,IntelliJ会自动创建运行配置。

#3


5  

Ah, my mistake:

啊,我的错误:

run com.example.MyVerticle should be the value of Program arguments: and not as VM options in the IntelliJ IDEA Run configuration.

com . example。运行MyVerticle应该是程序参数的值:而不是IntelliJ IDEA Run配置中的VM选项。

#4


2  

You can simply add a main and use deployVerticle() and then from there in IntelliJ you can Run or Debug it easily. With deployVerticle, you can pass a new instance of your main/bootstrap verticle or you can pass yourMainVerticle.class

您可以简单地添加一个main并使用deployVerticle(),然后在IntelliJ中,您可以轻松地运行或调试它。使用deployVerticle,您可以传递主/引导程序verticle的一个新实例,也可以传递main .class

public class VertxVerticleMain {

    public static void main(String[] args) {
        Vertx vertx = Vertx.vertx();

        vertx.deployVerticle(new MyVerticle());
       //vertx.deployVerticle(MyVerticle.class);

    }
}

#5


1  

You have to use this: org.vertx.java.platform.impl.cli.Starter as your Main Class in IntelliJ IDEA; and if you are using arguments and things like that you might want to use something like: runmod <groupId>~<artifactId>~<version> [-conf src/main/resources/your_config.json -cp]

您必须使用这个:org.vertx.java.platform.impl.cli。作为你在IntelliJ IDEA的主类;如果您正在使用参数或类似的东西,您可能希望使用以下内容:runmod ~ ~ [-conf src/main/resources/your_config]。json - cp)

Have a look at this project.

看看这个项目。

For Vert.x 3.0.0 you have to use this: io.vertx.core.Starter as your Main Class and run com.example.other.AnyVerticle as your Program arguments.

为绿色。x 3。0你必须使用这个:io.vertx。core。开始你的主课程,运行com.example.other。任何verticle作为你的程序参数。