I just created the bellow class.
public interface WebJarHandler {
static HttpHandler withLocation( webJarInternalLocation ) {
final ResourceManager resourceManager = loadResourceManagerFor( webJarInternalLocation );
return new ResourceHandler(resourceManager, new WebJarNotFound( context.fallbackHandler() ) )
}
static ResourceManager loadResourceManagerFor(String location) {
final File locationAsFile = new File(location);
if ( locationAsFile.exists() ) {
final boolean isCaseSensitive = !OS_NAME.contains("win");
return new FileResourceManager(locationAsFile, 100, isCaseSensitive );
}
final ClassLoader classLoader = SystemResource.class.getClassLoader();
return new ClassPathResourceManager( classLoader, location );
}
}
And used it just like this:
final String DEFAULT_WEBJAR_LOCATION = "META-INF/resources/webjars/";
final Undertow server = Undertow.builder()
.addHttpListener(8080, "localhost")
.setHandler( WebJarHandler.withLocation(DEFAULT_WEBJAR_LOCATION) ).build();
server.start();
// TODO: check syntax