Search code examples
javathorntail

How do I serve static content with thorntail


I have a new project created using the Thorntail Project Generator. I want to serve a small amount of static files such as html, images etc

How can I do this?


Solution

  • Assuming you build your project with Maven, you need to:

    • make sure that your Maven project is <packaging>war</packaging>
    • add a dependency on the io.thorntail:undertow fraction
    • put your static content into src/main/webapp (but not under src/main/webapp/WEB-INF)
    • if you also use JAX-RS, make sure that the JAX-RS application is not bound to /; for example, if you use the most common way of enabling JAX-RS (creating an Application subclass with the @ApplicationPath annotation), make sure that you don't have @ApplicationPath("/"), but something like @ApplicationPath("/api")

    I created a small example project here: https://github.com/rhoar-qe/thorntail-test-suite/tree/master/javaee/static-content

    Note that Thorntail is based on WildFly, and so includes the same servlet container: Undertow. If you have more elaborate needs, you can find articles about serving static content with servlet in general and Undertow in particular everywhere on the web, including here on StackOverflow.