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", whilehttp://localhost:9999/test will render test.html.
Any help will be appreciated.
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/c0710d0d-7ee6-4f0a-8cb8-d79e3afb1c08%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.