向GWT开发模式服务器(Jetty)添加外部资源



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

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

我知道(并使用)dev-mode-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配置文件。)

非常感谢!

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

然后,我可以通过我的一个配置文件轻松地配置静态文件的基本目录。我也可以做任意的事情,比如把几个目录混合在一起,或者从数据库中获取文件内容。。。

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

我正在工作的一个:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<Configure class="org.mortbay.jetty.webapp.WebAppContext">
        <New id="sampleDS" class="org.mortbay.jetty.plus.naming.Resource">            
            <Arg>java:jboss/datasources/sampleDS</Arg>
            <Arg>
                 <New class="oracle.jdbc.pool.OracleConnectionPoolDataSource">
                 <Set name="URL">jdbc:oracle:thin:@127.0.0.1:1521:ORCL</Set>                 
                 <Set name="User">user</Set>
                 <Set name="Password">pass</Set>
                 </New>
            </Arg>
        </New>
</Configure>
  1. 将其置于WEB-INF
  2. 下载[jetty-naming-6.1.12.jar][1][jetty-plus-6.1.12.jar][2],并将它们放在"WEB-INF\lib"下

重新启动eclipse并再次运行就可以了。

最新更新