Fat Jar 中的 Vertx Webroot [英] Vertx Webroot In Fat Jar

查看:57
本文介绍了Fat Jar 中的 Vertx Webroot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am building a fat jar for a Vertx-Web application. I would like to serve some static files. I packaged the jar file, with webroot folder. See below screenshot for my jar structure:

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

I was able to load the webroot/static/test.html file by doing:

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

但是,我无法让静态处理程序工作.以下是我的完整代码:

However, I am not able to get the static handler to work. Below is my full code:

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.

In the above example, http://localhost:9999/static/test.html will say "Not Found", while http://localhost:9999/test will render test.html.

任何帮助将不胜感激.

推荐答案

由 Vert.x 小组在 https://groups.google.com/forum/?fromgroups#!topic/vertx/yKInZuYcqDE.我的 webroot 应该看起来像webroot/test.html",而不是webroot/static/test.html".

Was answered by the Vert.x group at https://groups.google.com/forum/?fromgroups#!topic/vertx/yKInZuYcqDE. My webroot should look like "webroot/test.html", instead of "webroot/static/test.html".

这篇关于Fat Jar 中的 Vertx Webroot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆