简体   繁体   中英

Get maven-jetty-plugin to deploy-war and serve external static content at the same time

I'm writing integration tests for a web app using the maven-jetty-plugin. I'm using the deploy-war goal inside the pre-integration-test phase. The web app depends on another web application I would like to mock by serving static content from the same jetty instance.

here's the relevant part of my jetty config:

<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>

I've based this config on http://blog.markfeeney.com/2009/12/scala-lift-jetty-6-static-content-and.html , but the configurations for the context handler seems to be ignored. I can't find a trace of this in the log files, jetty returns 404 instead of static content, the web app itself is running.

What am I missing?

I figured it out:

the resourceHandlers configuration only works for the jetty:run goal, so I'm now working with an empty webapp in my test project, which overlays the webapp to be tested:

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM