java - Fat Jar 中的 Vertx Webroot

标签 java vert.x

我正在为 Vertx-Web 应用程序构建一个 fat jar。我想提供一些静态文件。我将jar文件打包,带有webroot文件夹。请参阅下面的屏幕截图了解我的 jar 结构:

enter image description here

我能够通过以下方式加载 webroot/static/test.html 文件:

routingContext.response().sendFile("webroot/static/test.html");

但是,我无法让静态处理程序正常工作。下面是我的完整代码:

package com.jdescript;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.http.HttpServer;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.handler.StaticHandler;

public class WebVerticle extends AbstractVerticle {
    private HttpServer httpServer;

    @Override
    public void start() throws IOException {
        httpServer = vertx.createHttpServer();

        Router router = Router.router(vertx);
        router.route("/static/*").handler(StaticHandler.create());

        router.route("/test").handler(routingContext -> {
            routingContext.response().sendFile("webroot/static/test.html");
        });

        httpServer.requestHandler(router::accept).listen(9999);
    }
}

在上面的示例中,http://localhost:9999/static/test.html会说“未找到”,而 http://localhost:9999/test将渲染 test.html。

任何帮助将不胜感激。

最佳答案

Vert.x 小组在 https://groups.google.com/forum/?fromgroups#!topic/vertx/yKInZuYcqDE 上进行了回答。我的 webroot 应该类似于“webroot/test.html”,而不是“webroot/static/test.html”。

关于java - Fat Jar 中的 Vertx Webroot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39782818/

相关文章:

java - Hadoop Oozie 工作流没有获得协调器属性

java - 如何从机场代码获取纬度和经度?

quarkus - 以 react 方式协调多个传出请求

javascript - 在基于 Vert.x 的应用程序中将从服务器接收到的数据传递给浏览器

Java 双缓冲

java - Android - 如何避免 Activity 之间的重复代码

java - Android clazz.getConstructors() 返回错误数量的构造函数,仅在实时应用程序中

java - Vertx 中的定时缓存

mysql - Quarkus 响应式(Reactive)客户端 MySql 客户端未插入记录

java.lang.UnsupportedClassVersionError : io/vertx/core/Starter Error 错误