IntelliJ和Vertx:如何运行org.vertx.java.deploy.impl.cli.Starter? [英] IntelliJ and Vertx: How to run org.vertx.java.deploy.impl.cli.Starter ?

查看:209
本文介绍了IntelliJ和Vertx:如何运行org.vertx.java.deploy.impl.cli.Starter?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Maven项目中有以下代码:

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);
    }
}

我在pom.xml中也有以下依赖项:

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>

我尝试使用以下配置在IntelliJ中运行Java应用程序:

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

我收到很多错误:


错误:(7,8)java:hello.Server不是抽象的,并且不会覆盖
io.vertx.core.Verticle中的
抽象方法stop(io.vertx.core.Future)错误: (12,57)java:找不到符号

符号:变量uri位置:变量req类型
io.vertx.core.http.HttpServerRequest错误:(14,48)java:不能找
符号符号:方法keySet()位置:接口
io.vertx.core.MultiMap错误:(17,20)java:找不到符号

符号:变量响应位置:
io.vertx.core.http.HttpServerRequest类型的变量req错误:(18,20)java:找不到
符号符号:v ariable响应位置:
的变量req io.vertx.core.http.HttpServerRequest错误:(9,9)java:找不到
符号符号:变量vertx location:class hello.Server

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

然而,当我从这里下载vert.x jar文件时:
http://vertx.io/download/

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.

可能我需要在pom.xml中有另一个依赖项,但我不知道它应该是什么。

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

推荐答案

你不应该有依赖:

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

因为它与Vert.x 1.2相关,而你的应用程序与3.x相关。在这种情况下,您的主要类应该是:

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

或者你可以从那里添加 main 方法并进行调试,例如:

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.

这篇关于IntelliJ和Vertx:如何运行org.vertx.java.deploy.impl.cli.Starter?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆