将外部资源添加到GWT dev模式服务器(Jetty) [英] Adding external resources to GWT dev mode server (Jetty)

查看:86
本文介绍了将外部资源添加到GWT dev模式服务器(Jetty)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要访问一些静态资源的GWT。我不想将这些资源放在实际的/ src / main / webapp目录中(注意:使用Maven和相应的布局),因为它们不是应用程序的一部分,而是数据的一部分。



我的问题不是在部署时如何让应用程序访问这些资源;这应该很容易通过Tomcat配置来完成。问题是如何让我的应用程序在开发过程中访问某些测试数据。我在我的GWT应用程序树之外的目录中有一些测试静态文件,并且想要配置GWT的开发模式Jetty服务器来访问这些资源。也就是说,我希望能够说mvn gwt:run(或者在Eclipse中以dev的模式运行或调试应用程序),并让服务器为这些静态资源提供服务。



<我知道(并使用)dev模式-noserver选项。但是,由于我正在修改服务器端代码以及客户端代码,因此每次服务器代码更改时重新部署服务器都是不现实的。



到目前为止,我一直在尝试的是在我的WEB-INF目录中创建一个jetty-web.xml文件,并添加一个新的上下文,以便服务器为我的资源提供服务。以下是我尝试失败的jetty-web.xml文件:

 < Configure id =parentHandlerclass =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 =parentHandlerclass =org.mortbay.jetty.handler.ContextHandler> 
< New id =newHandlerclass =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 =servername =server>
< Call name =setHandler>
< Arg>< Ref id =newHandler/>< / Arg>
< /通话>
< /获取>
< Ref id =newHandler>
< Set name =server>< Ref id =server/>< / Set>
< / Ref>
< / Configure>

... Jetty既不提供我的静态资料也不提供我的GWT应用程序。



有什么建议吗?我在做什么错了?



(注意:GWT开发模式使用Jetty的版本6或6.something,并以编程方式设置它,所以就我而言)



非常感谢!

解决方案

我喜欢使用的方法是编写一个可以流式传输任何文件的简单Servlet,类似于: http://www.exampledepot.com/egs/javax.servlet/GetImage.html ,并将其映射到我的web.xml中以获得特定的URL模式。



然后我可以通过我的一个配置文件轻松地为静态文件创建基础目录。我也可以做任意的东西,比如将几个目录混合在一起,或者从数据库中获取文件内容... ...

我更喜欢这种方法,因为它适用于所有的servlet任何环境中的容器。

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!

解决方案

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.

这篇关于将外部资源添加到GWT dev模式服务器(Jetty)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆