Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何运行嵌入式vert.x?_Java_Main_Vert.x - Fatal编程技术网

Java 如何运行嵌入式vert.x?

Java 如何运行嵌入式vert.x?,java,main,vert.x,Java,Main,Vert.x,我已经用main(args)编写了一个Groovy MainApp 当我启动它时,JVM直接退出(“JVM执行结束!”) 如何使用vert.x正确运行嵌入式HTTP服务器?我对Java也有同样的问题。在完成了所有的vert.x代码之后,我最终在.wait()中放入了一个对象。 看起来很糟糕,但实际上很有意义,因为它会触发我按需关闭服务器(通过.notify() 这是非常重要的,应该在Vert.x官方文档中提到。我面对了这一点。我试着传递主机名,但效果很好 Vertx Vertx=Vertx.ne

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

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


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

我对Java也有同样的问题。在完成了所有的vert.x代码之后,我最终在.wait()中放入了一个对象。 看起来很糟糕,但实际上很有意义,因为它会触发我按需关闭服务器(通过.notify()


这是非常重要的,应该在Vert.x官方文档中提到。

我面对了这一点。我试着传递主机名,但效果很好

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

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

摘自文档:

RouteMatcher routeMatcher = new RouteMatcher();

        // HTTP server
        HttpServer httpServer = vertx.createHttpServer();
        httpServer.requestHandler(routeMatcher);
httpServer.listen(7777);
只需等待System.in的输入:

// Prevent the JVM from exiting
System.in.read();

从文件中:

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

同样,vertx似乎没有时间在非集群模式下启动,jvm在此之前就停止了。我用
TimeUnit.SECONDS.sleep(1)解决了这个问题
最后:@yetanothercoder有什么理由不使用
。等待
/
。通知
// Prevent the JVM from exiting
System.in.read();