maven项目配置jetty8、jetty9

2019-09-25  本文已影响0人  likaizzk

1. jetty8配置

<plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>8.1.16.v20140903</version>
    <configuration>
        <!-- 新代码的扫描时间间隔(秒),值 <= 0 表示不扫描 -->
        <scanIntervalSeconds>10</scanIntervalSeconds>
        
        <stopPort>9999</stopPort>
        <webAppConfig>
            <contextPath>/goods</contextPath>
        </webAppConfig>
        <connectors>
            <!-- http配置 -->
            <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
                <port>9090</port>
                <maxIdleTime>60000</maxIdleTime>
            </connector>
            <!-- https配置 -->
            <connector implementation="org.eclipse.jetty.server.ssl.SslSelectChannelConnector">
                <port>9443</port>
                <password>changeit</password>
            </connector>
        </connectors>
    </configuration>
</plugin>

环境支持:Jdk 1.6+,Servlet 3.0,Tomcat 7+

补充:Jetty有一个问题,默认使用nio连接会把资源文件(html, css)锁定,解决方案是把nio改为bio:
变更前:

<!-- http配置 -->
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
    <port>9090</port>
    <maxIdleTime>60000</maxIdleTime>
</connector>
<!-- https配置 -->
<connector implementation="org.eclipse.jetty.server.ssl.SslSelectChannelConnector">
    <port>9443</port>
    <password>changeit</password>
</connector>

变更后:

<!-- http配置 -->
<connector implementation="org.eclipse.jetty.server.bio.SocketConnector">
    <port>9090</port>
    <maxIdleTime>60000</maxIdleTime>
</connector>
<!-- https配置 -->
<connector implementation="org.eclipse.jetty.server.ssl.SslSocketConnector">
    <port>9443</port>
    <password>changeit</password>
</connector>

2. jetty9配置

<plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>9.4.20.v20190813</version>
    <configuration>
        <scanIntervalSeconds>10</scanIntervalSeconds>
        <httpConnector>
            <port>9090</port>
        </httpConnector>
        <stopPort>9998</stopPort>
        <webApp>
            <contextPath>/customer</contextPath>
        </webApp>
    </configuration>
</plugin>

环境支持:Jdk 1.7+,Servlet 3.0+, Tomcat 8+

jetty 9.4.20.v20190813官方文档

3. jetty默认加载的配置

resources in ${project.basedir}/src/main/webapp
classes in ${project.build.outputDirectory}
web.xml in ${project.basedir}/src/main/webapp/WEB-INF/
上一篇下一篇

猜你喜欢

热点阅读