2017  Kodetalk | Feedback | Privacy Policy | Terms | About

How to configure Wildfly to serve static contents

JavaEE application running on Wildfly 8.0.0 Final.

The application uses a lot of images and I don"t want to store them in the database, so they are written to the hard disk.

How can we configure Wildfly/Undertow in order to serve these files (/var/images) on a certain URL, for example http://localhost:8080/myapplication/imagesFromDisk ?

Add another file handler and another location to the undertow subsystem in standalone.xml:

<server name="default-server">
    <http-listener name="default" socket-binding="http"/>
    <host name="default-host" alias="localhost">
        <location name="/" handler="welcome-content"/>
        <location name="/img" handler="images"/>
    <file name="welcome-content" path="${jboss.home.dir}/welcome-content" directory-listing="true"/>
    <file name="images" path="/var/images" directory-listing="true"/>

Answer is