user1670498
user1670498

Reputation: 389

Vertx Webroot In Fat 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:

enter image description here

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.

Upvotes: 0

Views: 929

Answers (1)

user1670498
user1670498

Reputation: 389

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

Upvotes: 1

Related Questions