欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Jetty与Maven集成

程序员文章站 2022-04-19 18:53:29
在项目中为了方便起见需要把服务器集成到Maven中以方便调试,   作为plugin集成: [html]   ...

在项目中为了方便起见需要把服务器集成到Maven中以方便调试,

 Jetty与Maven集成

作为plugin集成:


[html] 
<plugin> 
    <groupId>org.mortbay.jetty</groupId> 
    <artifactId>jetty-maven-plugin</artifactId> 
    <configuration> 
        <scanIntervalSeconds>10</scanIntervalSeconds> 
        <webAppConfig> 
            <contextPath>/web</contextPath> 
            <!-- 额外的ClassPath配置,路N多的properties文件等 --> 
            <extraClasspath>properties</extraClasspath> 
        </webAppConfig> 
        <contextHandlers> 
            <!-- 子项目依赖,或者需要加多个项目到这一个jetty运行环境里面 --> 
            <contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext"> 
                <war>../subweb/src/main/webapp</war> 
                <contextPath>/subweb</contextPath> 
            </contextHandler> 
        </contextHandlers> 
        <systemProperties> 
            <systemProperty> 
                <name>catalina.base</name> 
                <value>${basedir}/target</> 
            </systemProperty> 
        </systemProperties> 
        <connectors> 
            <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector"> 
                <port>8080</port> 
                <maxIdleTime>400000</maxIdleTime> 
            </connector> 
        </connectors> 
    </configuration> 
</plugin> 
直接在项目下运行mvn jetty:run

作为Maven参数集成:

[html] 
<profiles> 
    <profile> 
        <id>run-jetty</id> 
        <build> 
            <plugins> 
                <plugin> 
                     <groupId>org.mortbay.jetty</groupId> 
                     <artifactId>jetty-maven-plugin</artifactId> 
                     <configuration> 
                         <scanIntervalSeconds>10</scanIntervalSeconds> 
                         <webAppConfig> 
                             <contextPath>/web</contextPath> 
                             <extraClasspath>properties</extraClasspath> 
                         </webAppConfig> 
                         <contextHandlers> 
                             <contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext"> 
                                 <war>../subweb/src/main/webapp</war> 
                                 <contextPath>/subweb</contextPath> 
                             </contextHandler> 
                        </contextHandlers> 
                        <systemProperties> 
                            <systemProperty> 
                                <name>catalina.base</name> 
                                <value>${basedir}/target</> 
                            </systemProperty> 
                        </systemProperties> 
                        <connectors> 
                            <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector"> 
                               <port>8080</port> 
                               <maxIdleTime>400000</maxIdleTime> 
                           </connector> 
                        </connectors> 
                    </configuration> 
                </plugin> 
            </plugins> 
        </build> 
    <profile> 
<profiles> www.2cto.com

项目下运行 mvn -DskipTests=true clean test -Prun-jetty

http://www.devhup.com/?p=140

作者:devhubs