Maven中配置jetty插件

时间:2023-01-18 21:48:15

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.eclipse.jetty.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.