码迷,mamicode.com
首页 > 其他好文 > 详细

在maven中配置jetty

时间:2016-06-14 15:59:06      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:

pom.xml

 

<build>
        <finalName>/xxx</finalName>
        <plugins>
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>8.1.9.v20130131</version>
                <configuration>
                    <webApp>
                        <contextPath>/xxx</contextPath>
                    </webApp>
                    <connectors>
                        <connector implementation="org.eclipse.jetty.server.bio.SocketConnector">
                            <port>8081</port>
                            <maxIdleTime>60000</maxIdleTime>
                        </connector>
                        <connector implementation="org.eclipse.jetty.server.ssl.SslSocketConnector">
                            <port>8443</port>
                            <maxIdleTime>60000</maxIdleTime>
                            <password>123456</password>
                            <keyPassword>123456</keyPassword>
                            <keystore>${project.basedir}/src/test/resources/jetty.keystore</keystore>
                        </connector>
                    </connectors>
                    <systemProperties>
                        <systemProperty>
                            <!--一般服务器默认是ISO-8859-1编码-->
                            <name>org.mortbay.util.URI.charset</name>
                            <value>ISO-8859-1</value>
                        </systemProperty>
                    </systemProperties>
                    <!-- 从8.x开始,如果你的web项目中不包含数据库访问(或者说没有事务管理器)的话,在其启动时会提示找不到事务管理器
                     启动过程会暂停十几秒,在反复调试代码时很浪费时间,因此加入如下的配置,这个配置文件没有其他用处-->
                    <contextXml>${project.basedir}/src/test/resources/jetty-context.xml</contextXml>
                </configuration>
            </plugin>

            <!-- 密钥库生成器 也可以使用jdk keytool.exe生成密钥库-->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>keytool-maven-plugin</artifactId>
                <version>1.5</version>
                <executions>
                    <execution>
                        <phase>generate-resources</phase>
                        <id>clean</id>
                        <goals>
                            <goal>clean</goal>
                        </goals>
                    </execution>
                    <execution>
                        <phase>generate-resources</phase>
                        <id>genkey</id>
                        <goals>
                            <goal>generateKeyPair</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <keystore>${project.basedir}/src/test/resources/jetty.keystore</keystore>
                    <dname>CN=xxx,OU=xxx,O=xxx,L=xxx,ST=xxx,C=cn</dname>
                    <keypass>123456</keypass>
                    <storepass>123456</storepass>
                    <alias>jetty8</alias>
                    <keyalg>RSA</keyalg>
                </configuration>
            </plugin>
        </plugins>
    </build>


jetty-context.xml

 

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
    <Call name="setAttribute">
        <Arg>org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern</Arg>
        <Arg>.*/.*jsp-api-[^/]\.jar$|./.*jsp-[^/]\.jar$|./.*taglibs[^/]*\.jar$</Arg>
    </Call>
</Configure>

 

 

注意:

1、jetty 9.0以后就不能直接配置在pom文件中。

2、jetty的keystore需要指定RSA算法。

3、每次编译的时候,keytool-maven-plugin都会重新生成keystore,所以,可以再生成keystore后删除这个插件配置。

4、org.eclipse.jetty.server.bio.SocketConnector和org.eclipse.jetty.server.ssl.SslSocketConnector不会锁定资源文件(html、css、js、图片等),但是org.eclipse.jetty.server.nio.SelectChannelConnector和org.eclipse.jetty.server.ssl.SslSelectChannelConnector会锁定资源文件,两者是表示http和https的connector.

在maven中配置jetty

标签:

原文地址:http://www.cnblogs.com/gjb724332682/p/5583949.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!