将外部资源添加到 GWT 开发模式服务器 (Jetty)
我有一个 GWT 需要访问一些静态资源。我不想将这些资源放在实际的 /src/main/webapp 目录中(注意:使用 Maven 和相应的布局),因为它们不是应用程序的一部分,而是数据的一部分。
我的问题不是如何让应用程序在部署时访问这些资源;而是如何让应用程序在部署时访问这些资源。通过 Tomcat 配置应该很容易做到。相反,问题是如何让我的应用程序在开发过程中访问一些测试数据。我的 GWT 应用程序树外部的目录中有一些测试静态文件,并且想要配置 GWT 的开发模式 Jetty 服务器来访问这些资源。也就是说,我希望能够说 mvn gwt:run (或从 Eclipse 在开发模式下运行或调试应用程序),并让服务器提供这些静态资源。
我了解(并使用)开发模式 -noserver 选项。但是,由于我对服务器端代码以及客户端代码进行了大量修改,因此每次服务器代码更改时都重新部署服务器是不切实际的。
到目前为止,我一直在尝试在 WEB-INF 目录中创建一个 jetty-web.xml 文件,并添加一个新的上下文,以便服务器将为我的资源提供服务。以下是我失败的 jetty-web.xml 尝试:
<Configure id="parentHandler" class="org.mortbay.jetty.handler.ContextHandler">
<Set name="contextPath">/static_resources</Set>
<Set name="resourceBase">/real/filesystem/path/to/static/resources/</Set>
<Set name="handler">
<New class="org.mortbay.jetty.handler.ResourceHandler">
<Set name="cacheControl">max-age=3600,public</Set>
</New>
</Set>
</Configure>
如果我将其放入 jetty-web.xml 中,那么当我启动开发模式时,Jetty 会为我的外部资源提供服务,但不会为我的 GWT 应用程序提供服务。
另一方面,如果我这样做......
<Configure id="parentHandler" class="org.mortbay.jetty.handler.ContextHandler">
<New id="newHandler" class="org.mortbay.jetty.handler.ContextHandler" >
<Set name="contextPath">/static_resources</Set>
<Set name="resourceBase">/real/filesystem/path/to/static/resources/</Set>
<Set name="handler">
<New class="org.mortbay.jetty.handler.ResourceHandler">
<Set name="cacheControl">max-age=3600,public</Set>
</New>
</Set>
</New>
<Get id="server" name="server">
<Call name="setHandler">
<Arg><Ref id="newHandler" /></Arg>
</Call>
</Get>
<Ref id="newHandler">
<Set name="server"><Ref id="server" /></Set>
</Ref>
</Configure>
Jetty 既不服务于我的静态内容,也不服务于我的 GWT 应用程序。
有什么建议吗?我做错了什么?
(注意:GWT 开发模式使用 Jetty 版本 6 [或 6.something],并以编程方式设置它,因此据我所知,没有读入其他 Jetty 配置文件。)
非常感谢!
I have a GWT that needs to access some static resources. I don't want to place these resources in the actual /src/main/webapp directory (note: using Maven and corresponding layout) because they're not part of the app, but part of the data.
My problem is not how to give the application access to these resources at deployment time; that should be easy to do via Tomcat configuration. Rather the problem is how to give my app access to some test data during development. I have some test static files in a directory outside my GWT app tree, and would like to configure GWT's dev mode Jetty server to access those resources. That is, I want to be able to say mvn gwt:run (or run or debug the app in dev mode from Eclipse), and have the server serve those static resources.
I know about (and use) the dev mode -noserver option. However, since I'm modifying the server-side code a lot, along with the client code, it's not practical to redeploy the server every time the server code changes.
So far what I've been trying is to create a jetty-web.xml file in my WEB-INF directory, and add a new context so the server will serve my resources. Here are my failed jetty-web.xml attempts:
<Configure id="parentHandler" class="org.mortbay.jetty.handler.ContextHandler">
<Set name="contextPath">/static_resources</Set>
<Set name="resourceBase">/real/filesystem/path/to/static/resources/</Set>
<Set name="handler">
<New class="org.mortbay.jetty.handler.ResourceHandler">
<Set name="cacheControl">max-age=3600,public</Set>
</New>
</Set>
</Configure>
If I put that in jetty-web.xml, then when I start dev mode, Jetty does serve my external resources, but doesn't serve my GWT app.
On the other hand, if I do this...
<Configure id="parentHandler" class="org.mortbay.jetty.handler.ContextHandler">
<New id="newHandler" class="org.mortbay.jetty.handler.ContextHandler" >
<Set name="contextPath">/static_resources</Set>
<Set name="resourceBase">/real/filesystem/path/to/static/resources/</Set>
<Set name="handler">
<New class="org.mortbay.jetty.handler.ResourceHandler">
<Set name="cacheControl">max-age=3600,public</Set>
</New>
</Set>
</New>
<Get id="server" name="server">
<Call name="setHandler">
<Arg><Ref id="newHandler" /></Arg>
</Call>
</Get>
<Ref id="newHandler">
<Set name="server"><Ref id="server" /></Set>
</Ref>
</Configure>
...Jetty serves neither my static stuff nor my GWT app.
Any suggestions? What am I doing wrong?
(Note: GWT dev mode uses version 6 [or 6.something] of Jetty, and sets it up programmatically, so as far as I can see, no other Jetty config files are read in.)
Many thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我喜欢使用的方法是编写一个简单的 Servlet,它可以流式传输任何文件,类似于: http://www.exampledepot.com/egs/javax.servlet/GetImage.html,并将其在我的 web.xml 中映射到某些 URL 模式。
然后我可以轻松地通过我的配置文件之一配置静态文件的基本目录。我还可以执行任意操作,例如将多个目录混合在一起,或者从数据库获取文件内容,...
我更喜欢这种方法,因为它适用于任何环境中的所有 servlet 容器。
The approach I like to use is to write a simple Servlet which can stream any file, similar to: http://www.exampledepot.com/egs/javax.servlet/GetImage.html, and map it in my web.xml to certain URL patterns.
Then I can easily make the base directory for the static files configurable via one of my configuration files. I can also do arbitrary stuff like mixing several directories together, or getting the file contents from a DB, ...
I prefer this approach, because it works with all servlet containers in any environment.
我的工作方法:
WEB-INF
[jetty-naming-6.1.12.jar][1]
和[jetty-plus-6.1.jar] 下。 12.jar][2]
并将它们放在“WEB-INF\lib”下重新启动 eclipse 并再次运行应该可以解决问题。
My working one:
WEB-INF
[jetty-naming-6.1.12.jar][1]
and[jetty-plus-6.1.12.jar][2]
and put them under `WEB-INF\lib'Restart eclipse and run again should do the trick.