0

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: enter image description here

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.

CrazySynthax
  • 13,662
  • 34
  • 99
  • 183
  • Related https://stackoverflow.com/questions/32205477/how-to-start-vert-x-server-from-intellij-idea – Jonas May 31 '17 at 12:52

1 Answers1

2

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.

Paulo Lopes
  • 5,845
  • 22
  • 31
  • I get an Error: io.vertx.core.Launcher not found in module 'VertxTry' – CrazySynthax May 31 '17 at 12:05
  • the launcher class is part of `vertx-core` which is in your project. Also note that you have messed up classpath and imports, you have a dependency on 3.4.1 but you're importing 1.2.3 classes. The 3.4.1 classes live on package `io.vertx...` while they used to live in `org.vertx...` during 1.2.3 – Paulo Lopes May 31 '17 at 12:42