IntelliJ and Vertx: How to run org.vertx.java.deploy.impl.cli.Starter ?

拈花ヽ惹草 提交于 2019-12-12 05:48:43

问题


I have the following code inside Maven project:

package hello;

import org.vertx.java.core.Handler;
import org.vertx.java.core.http.HttpServerRequest;
import org.vertx.java.deploy.Verticle;


public class Server extends Verticle {
    public void start() {
        vertx.createHttpServer().requestHandler(new Handler<HttpServerRequest>() {
            @Override
            public void handle(HttpServerRequest req) {
                System.out.println("Got request: " + req.uri);
                System.out.println("Headers are: ");
                for (String key : req.headers().keySet()) {
                    System.out.println(key + ":" + req.headers().get(key));
                }
                req.response.headers().put("Content-Type", "text/html; charset-UTF-8");
                req.response.end("<html><body><h1>Hello from vert.x!</h1></body></html>");
            }
        }).listen(4000);
    }
}

I also have the following dependency in pom.xml:

<dependency>
            <groupId>io.vertx</groupId>
            <artifactId>vertx-core</artifactId>
            <version>3.4.1</version>
        </dependency>

        <dependency>
            <groupId>org.vert-x</groupId>
            <artifactId>vertx-platform</artifactId>
            <version>1.2.3.final</version>
        </dependency>

I try to run Java application in IntelliJ with the following configuration:

and I get many errors:

Error:(7, 8) java: hello.Server is not abstract and does not override abstract method stop(io.vertx.core.Future) in io.vertx.core.Verticle Error:(12, 57) java: cannot find symbol
symbol: variable uri location: variable req of type io.vertx.core.http.HttpServerRequest Error:(14, 48) java: cannot find symbol symbol: method keySet() location: interface io.vertx.core.MultiMap Error:(17, 20) java: cannot find symbol
symbol: variable response location: variable req of type io.vertx.core.http.HttpServerRequest Error:(18, 20) java: cannot find symbol symbol: variable response location: variable req of type io.vertx.core.http.HttpServerRequest Error:(9, 9) java: cannot find symbol symbol: variable vertx location: class hello.Server

However, when I download vert.x jar files from here: http://vertx.io/download/

and put them in the project structure, then the same code compiles successfully.

Probably I need another dependency in pom.xml, but I don't know what it should be.


回答1:


You shouldn't have the dependency:

    <dependency>
        <groupId>org.vert-x</groupId>
        <artifactId>vertx-platform</artifactId>
        <version>1.2.3.final</version>
    </dependency>

Since it related to Vert.x 1.2 and your application in on 3.x. In this case your main class should be:

    io.vertx.core.Launcher

Alternatively you could add a main method and debug from there, for example:

public class Server extends Verticle {
  public static void main(String[] args) {
    Vertx.vertx().deployVerticle(new Server());
  }
}

Now you don't need to worry about adding launcher profiles, just right click and run/debug.



来源:https://stackoverflow.com/questions/44283326/intellij-and-vertx-how-to-run-org-vertx-java-deploy-impl-cli-starter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!