配置 Maven 码头插件:
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1H.14.1</version>
<configuration>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>8085</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
</configuration>
</plugin>
</plugins>
如果要使用较新版本的 jetty 插件,请使用以下配置:
来自http://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html:
您可以改为在标准 jetty xml 配置文件中配置连接器,并将其位置放入 jettyXml 参数中。请注意,从 jetty-9.0 开始,不再可以直接在 pom.xml 中配置 https 连接器:您需要使用 jetty xml 配置文件来执行此操作。
就像是:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.0.5.v20130815</version>
<configuration>
<jettyXml>src/main/resources/jetty.xml</jettyXml>
<webApp>
<contextPath>/yourCtxPath</contextPath>
</webApp>
</configuration>
</plugin>
可以使用 jetty.xml 文件内容来解决问题:
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Call id="httpsConnector" name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.ServerConnector">
<Arg name="server"><Ref refid="Server" /></Arg>
<Set name="host"><Property name="jetty.host" /></Set>
<Set name="port"><Property name="jetty.port" default="8085" /></Set>
<Set name="idleTimeout">30000</Set>
</New>
</Arg>
</Call>
</Configure>
查看 'mvn jetty:run' 之后的日志,最后应显示如下内容:
2013-09-05 09:49:05.047:INFO:oejs.ServerConnector:main: Started ServerConnector@a6e9cb4{HTTP/1.1}{0.0. 0.0: 8085 }
对于此版本的插件,您将需要使用 maven 3 和 java 7。