我正在使用maven-jetty-plugin为一个web应用程序编写集成测试。我在预集成测试阶段使用了deploy-war目标。web应用程序依赖于另一个web应用程序,我想通过提供来自同一jetty实例的静态内容来模拟。
下面是我的jetty配置的相关部分:
<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而不是静态内容,web应用程序本身正在运行。
我遗漏了什么?
发布于 2012-03-30 16:44:38
我想通了:
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>https://stackoverflow.com/questions/9926741
复制相似问题