Is there an easy way to map a directory in the web.xml or other deployment descriptor (jetty.xml, etc) files?
For example, if I have a directory /opt/files/ is there a way that I can access its files and sub-directories by visiting http://localhost/some-mapping/? It strikes me that there should be some simple way of doing this, but I haven't been able to find out how (via google, stackoverflow, etc). All I've found are servlets that mimic fileservers, which is not what I would like.
For reference I am using jetty on an AIX box.
No idea how to do it with Jetty, but in Tomcat you can just add a new
<Context>
toserver.xml
:This way it's accessible by
http://example.com/files/...
. See if something similar exist for Jetty.Update: after Googling, the "normal Java code" equivalent would be something like:
Now yet to translate that into
jetty.xml
flavor. I am a bit guessing based on the documentation and examples found on the web, so don't pin me on it:Another possibility may be this:
I don't know that you can do that as a URL mapping, however files and folders in the same directory that your web.xml file is in will be accessible in the way you describe, although you can't control the mapping under your webapp.
Does that suit your needs?
After some more fiddling around, the best way to do this (for jetty) is to deploy a descriptor in the context directory that looks like the following...
I hope that this helps someone else!