同时从两个目录提供 jetty webapp
在开发中我使用jetty作为servlet容器。我有以下开发配置:
- 主项目具有 wabapp 目录
- 派生项目,该项目覆盖 webapp 目录中的一些文件
由于向 jetty 提供了适当的 WebAppContext
,主项目 webapp 可以在开发模式下启动。
现在我想类似地启动派生项目,假设发出请求时,会尝试:
- 从派生项目的 webapp 目录中获取资源(
- 如果不存在),从主项目的 webapp 目录中获取资源
我知道这是可能的重写 WebAppContext#getResource()
方法,但是我们在项目中使用的一些库似乎自己对 wabapp 目录执行 IO 操作。例如,通过调用 ServletContext#getRealPath("/")
,然后读取文件而不使用 ServletContext#getResource()
方法。这个问题可以通过 File
之上的一些虚拟文件系统在较低级别上解决,但是 JDK 1.6 似乎不支持它,有什么建议吗?
In development I use jetty as the servlet container. I have the following development configuration:
- master project which has wabapp directory
- derived project which overrides some of the files in webapp directory
The master project webapp can be started in development mode thanks to providing appropriate WebAppContext
to jetty.
Now I want to start derived project analogously, assuming that when request is made, there is an attempt to:
- get resource from webapp directory of derived project
- if it does not exists, get it from webapp directory of master project
I know that it is possible to override WebAppContext#getResource()
method, however some libraries we use in the project seem to perform IO operations on wabapp directory on their own. For example by calling ServletContext#getRealPath("/")
, and then reading files without use of ServletContext#getResource()
method. The problem could be solved on lower level by some virtual file system on top of File
, however it does not seem to be supported in JDK 1.6, any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎使用像
ResourceCollection
这样的东西就足够了:http://download.eclipse.org/jetty/stable-7/apidocs/org/eclipse/jetty/util/resource/ResourceCollection.html
不幸的是,GWT 的 DevMode我使用的是基于jetty 6,其中ResourceCollection不可用。我自己扩展了
Resource
类,并与自己的 GWTJettyLauncher
一起扩展,并且感谢在DefaultServlet
上设置resourceBase
的小技巧。 code> 通过反射,我能够同时从两个目录提供 webapp 服务。It seems that using something like
ResourceCollection
is sufficient:http://download.eclipse.org/jetty/stable-7/apidocs/org/eclipse/jetty/util/resource/ResourceCollection.html
Unfortunately the GWT's DevMode which I use is based on jetty 6, where ResourceCollection is unavailable. I extended the
Resource
class myself, and together with own GWTJettyLauncher
, and thanks to small trick with settingresourceBase
onDefaultServlet
via reflection, I was able to serve webapp from two directories simultaneously.