美文网首页
maven项目配置jetty8、jetty9

maven项目配置jetty8、jetty9

作者: likaizzk | 来源:发表于2019-09-25 16:15 被阅读0次

    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/
    

    相关文章

      网友评论

          本文标题:maven项目配置jetty8、jetty9

          本文链接:https://www.haomeiwen.com/subject/vnqwuctx.html