2017-05-31 66 views
0

我有Maven的项目中下面的代码:IntelliJ和Vertx:如何运行org.vertx.java.deploy.impl.cli.Starter?

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中以下依赖性:

<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应用程序: enter image description here

,我也得到了许多错误:

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/

,并把它们在项目结构,则同样的代码编译成功。

大概我需要pom.xml中的另一个依赖项,但我不知道它应该是什么。

+0

相关https://stackoverflow.com/questions/32205477/how-to-start-vert-x-server-from-intellij-idea – Jonas

回答

2

你不应该依赖:

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

因为它涉及到Vert.x 1.2和您的应用程序在3.x中在这种情况下,你的主类应该是:

io.vertx.core.Launcher 

或者,你可以从那里添加一个main方法和调试,例如:

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

现在你不必担心将启动配置文件,只需右键单击并运行/调试。

+0

我得到一个错误: io.vertx.core.Launcher中找不到模块'VertxTry' – CrazySynthax

+0

启动程序类是您的项目中的'vertx-core'的一部分。还要注意,你已经搞砸了类路径和导入,你对3.4.1有依赖性,但是你正在导入1.2.3类。 3.4.1课程生活在'io.vertx'包',而它们曾经住在1.2.3中的'org.vertx ...' –