有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何运行嵌入式vert。十、

我已经用main(args)编写了一个Groovy MainApp

当我启动它时,JVM直接退出(“JVM执行结束!”

import org.vertx.groovy.core.Vertx

class MainApp {

    public static void main(String[] args) {

        Vertx vertx = VertxFactory.newVertx();

        vertx.createHttpServer().requestHandler{ request -> 
            println "A request has arrived on the server!" 
        }.listen(8080)

        println "End of JVM execution !"
    }
}

如何使用vert正确运行嵌入式HTTP服务器。x


共 (5) 个答案

  1. # 1 楼答案

    从文件中:

    all Vert.x threads are daemon threads and they will not prevent the JVM for exiting. Therefore you must ensure that the main() method does not run to completion, e.g. in this example we have used System.in.read() to block the main thread waiting for IO from the console.
    

    因此,您需要在主方法末尾添加以下内容,如下所示:

    // Prevent the JVM from exiting
    System.in.read();
    
  2. # 3 楼答案

    RouteMatcher routeMatcher = new RouteMatcher();
    
            // HTTP server
            HttpServer httpServer = vertx.createHttpServer();
            httpServer.requestHandler(routeMatcher);
    httpServer.listen(7777);
    
  3. # 4 楼答案

    我对Java也有同样的问题。我最后在里面放了一个东西。在所有的顶点之后等待()。x代码。 看起来很糟糕,但实际上很有意义,因为它会触发我按需关闭服务器(通过.notify()

    这不是小事,应该在Vert上提及。十正式文件

  4. # 5 楼答案

    我面对这个问题。我试着传递主机名,但效果很好

    Vertx Vertx=Vertx。newVertx(“主机名”

    我猜在本地运行时,确定IP地址时会出现一些问题,但它失败了