I'm writing a simple reporting web application using JAX-RS and AngularJS deployed to IBM WebSphere Application Server. Since it is really very simple I try to keep as little dependencies as possible, so I am not using any fancy framework server-side.
For serving static resources I wrote this controller. I keep them in src/main/resources
folder.
@Path("/")
public class Assets {
@GET
@Path("{path:.*\\.js}")
public Response javascript(@PathParam("path") String resourceName) {
return serveResource(resourceName, "application/javascript");
}
private Response serveResource(String resourceName, String contentType) {
InputStream inputStream =
getClass().getClassLoader().getResourceAsStream(resourceName);
return Response.ok(inputStream)
.header(HttpHeaders.CONTENT_TYPE, contentType)
.build();
}
}
So far so good.
As I use several JavaScript libraries (jQuery, Underscore.js, AngularJS), I wanted to make use of WebJars. According to documentation on webjars.org:
With any Servlet 3 compatible container, the WebJars that are in the
WEB-INF/lib
directory are automatically made available as static resources. This works because anything in aMETA-INF/resources
directory in a JAR inWEB-INF/lib
is automatically exposed as a static resource.
When I put corresponding WebJars into my pom.xml
, things stopped working. This is what I found out so far:
- WebJars are, of course, present in the resulting
.war
package, inWEB-INF/lib
folder. ClassLoader
used in myserveResource
method claims in has all WebJars in its classpath.- The
ClassLoader
's implementation iscom.ibm.ws.classloader.CompoundClassLoader
. - None of the resources in present in WebJars in
META-INF/resources
folder is visible to theClassLoader
. None.
How can I make the class loader see the resources in the WebJars?