Vertx Webroot In Fat Jar

╄→гoц情女王★ 提交于 2019-12-10 12:13:37

问题


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:

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

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

Any help will be appreciated.


回答1:


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".



来源:https://stackoverflow.com/questions/39782818/vertx-webroot-in-fat-jar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!