2017-05-31 32 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 ...' –