I'm aware of similar questions here and here. And yet IMHO the issue is not yet fully covered, or at least it's still not working smoothly for me :(
What is the need:
I'd like to build a JAR packaged library, that will be used like a shared component in several WebApps, bringing within it the server logic as well as the relevant UI (web-components). Think of a UserService
providing servlet/resource for login
and signup
calls from the server side perspective, while having UI components for end-to-end solution for any WebApp in the whole eco system from the client side.
So far:
Seems like this requirement exactly is addressed by a feature in Servlet 3.0 spec dealing with servlet web resources found in JARs under the path META-INF/resources
.
I, seemingly, did exactly as it said, structuring the ui-components.jar
having META-INF/resources/ui-commons/...
under the root and configuring the following in the web.xml
:
<servlet>
<servlet-name>ui-commons</servlet-name>
<servlet-class>org.eclipse.jetty.servlet.DefaultServlet</servlet-class>
<init-param>
<param-name>relativeResourceBase</param-name>
<param-value>/WEB-INF/lib/ui-components.jar!META-NF/resources</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>ui-commons</servlet-name>
<url-pattern>/ui-commons/*</url-pattern>
</servlet-mapping>
This definition comes before the default servlet definition serving the rest of the regular WebApp resources found in WAR as usual.
And yet, any request for the resources in that JAR ends up with 404.
Servlet version is 3.1
.
Jetty 9.4
.
It is NOT embedded Jetty, nothing fancy, but please pay attention to the notice below regarding the maven plugin.
Notice:
It might somehow be related to the fact that I'm currently trying to run this whole setup with jetty-maven-plugin
, which is serving resources from the sources.
- I've tried to drop the said JAR into the
src/main/resources/WEB-INF/lib...
manually - no success