获取maven-jetty-plugin来部署war并同时提供外部静态内容

时间:2012-03-29 13:50:58

标签: web-applications maven jetty

我正在使用maven-jetty-plugin为web应用编写集成测试。我在预集成测试阶段使用部署战争目标。 Web应用程序依赖于我想通过从同一个jetty实例提供静态内容来模拟的另一个Web应用程序。

这是我的码头配置的相关部分:

<execution>
    <id>start-jetty</id>
    <phase>pre-integration-test</phase>
    <goals>
        <goal>deploy-war</goal>
    </goals>
    <configuration>
        <connectors>
            <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
                <port>${jetty.port}</port>
            </connector>
        </connectors>
        <daemon>true</daemon>
        <webApp>${build.directory}/motown2-war.war</webApp>
        <webAppConfig>
            <extraClasspath>${basedir}/target/classes/;${basedir}/target/test-classes</extraClasspath>
            <contextPath>/${context.path}</contextPath>
        </webAppConfig>
        <contextHandlers>           
            <contextHandler implementation="org.mortbay.jetty.webapp.WebAppContext">
                <contextPath>/other</contextPath>
                <resourceBase>/opt/data</resourceBase>
            </contextHandler>
        </contextHandlers>
    </configuration>
</execution>

我已根据此配置 http://blog.markfeeney.com/2009/12/scala-lift-jetty-6-static-content-and.html, 但是上下文处理程序的配置似乎被忽略了。我不能 在日志文件中找到这个跟踪,jetty返回404而不是静态 内容,网络应用程序本身正在运行。

我错过了什么?

1 个答案:

答案 0 :(得分:2)

我明白了:

resourceHandlers配置仅适用于jetty:run目标,所以我现在 在我的测试项目中使用空webapp,它将webapp覆盖到 测试:

<execution>
    <id>start-jetty</id>
    <phase>pre-integration-test</phase>
    <goals>
        <goal>run</goal>
    </goals>
    <configuration>
        <connectors>
            <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
                <port>${jetty.port}</port>
            </connector>
        </connectors>
        <daemon>true</daemon>
        <webApp>${build.directory}/motown2-war.war</webApp>
        <webAppConfig>
            <extraClasspath>${basedir}/target/classes/;${basedir}/target/test-classes</extraClasspath>
            <contextPath>/${context.path}</contextPath>
            <baseResource implementation="org.mortbay.resource.ResourceCollection">
                <resourcesAsCSV>../motown2-war/src/main/webapp,src/main/webapp</resourcesAsCSV>
            </baseResource>
        </webAppConfig>
        <contextHandlers>           
            <contextHandler implementation="org.mortbay.jetty.webapp.WebAppContext">
                <contextPath>/other</contextPath>
                <resourceBase>/opt/data</resourceBase>
            </contextHandler>
        </contextHandlers>
    </configuration>
</execution>