Maven Coordinates

To enable Static Content Support add the following dependency to your project’s pom.xml (see Managing Dependencies).

<dependency>
    <groupId>io.helidon.webserver</groupId>
    <artifactId>helidon-webserver-static-content</artifactId>
</dependency>
Copied

Static Content Support

Use the io.helidon.webserver.staticcontent.StaticContentSupport class to serve files and classpath resources. StaticContentSupport can be created for any readable directory or classpath context root and registered on a path in Routing.

You can combine dynamic handlers with StaticContentSupport objects: if no file matches the request path, then the request is forwarded to the next handler.

Registering Static Content

To register static content based on a file system (/pictures), and classpath (/):

Routing.builder()
       .register("/pictures", StaticContentSupport.create(Paths.get("/some/WEB/pics"))) 
       .register("/", StaticContentSupport.builder("/static-content") 
                                   .welcomeFileName("index.html") 
                                   .build());
Copied
  • Create a new StaticContentSupport object to serve data from the file system, and associate it with the "/pictures" context path.
  • Create a StaticContentSupport object to serve resources from the contextual ClassLoader. The specific classloader can be also defined. A builder lets you provide more configuration values.
  • index.html is the file that is returned if a directory is requested.

A StaticContentSupport object can be created using create(…​) factory methods or a builder. The builder lets you provide more configuration values, including welcome file-name and mappings of filename extensions to media types.