I have a WAR (being served through Embedded Jetty) that I'd like to include static files outside the WAR. My goals are:
- Serve static files from a path outside the WAR, relative to the directory the Embedded Jetty is running. So, if I invoke the jar in
/srv/app
, I'd like to configure a URL ofhttp://myapp.com/static/js/my.js
to serve/src/app/public/js/my.js
. - Secure: No directory listings or
../
path escapes - Not reinvent the wheel: I don't want to write a new Servlet, but rather harness existing capabilities
- Ideally (not required): Shadow the static content in the WAR, so that if I have a
/src/app/public/index.html
, that file will be served, and, if not existent, the WAR'sindex.html
will be served.
Here's what I examined, and where I'm stuck:
- DefaultServlet: Seems ideal, but, I can't find any way to have it serve files outside the WAR. Is there a way for the DefaultServlet to serve static content outside the WAR, with paths relative to the app's pwd?
- Configuring Jetty, as described in https://www.eclipse.org/jetty/documentation/current/static-content-deployment.html ; this would seem to be ideal, but, when copied in, didn't seem to do anything (it was a NOOP).
- ResourceHandler: Is this the right way to do it? I wasn't able to figure out how to use this to make my goals