Jetty7/8的Maven插件下载:http://mvnrepository.com/artifact/org.mortbay.jetty/jetty-maven-plugin
Jetty9的Maven插件下载:http://mvnrepository.com/artifact/org.eclipse.jetty/jetty-maven-plugin
Jetty7/8 的Maven插件配置:http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin
Jetty9 的Maven插件配置:http://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html
http://www.eclipse.org/jetty/documentation/9.2.10.v20150310/jetty-maven-plugin.html(指定版本)
Jetty 各个版本的限制:
http://wiki.eclipse.org/Jetty/Starting/Jetty_Version_Comparison_Table

以Jetty8为例。
1.简单配置:
<plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>8.1.16.v20140903</version> <configuration> <scanIntervalSeconds>10</scanIntervalSeconds> <webApp> <contextPath>/test</contextPath> </webApp> </configuration> </plugin>
scanIntervalSeconds 如果检测到项目有更改则自动热部署,每隔n秒扫描一次。默认为0,即不扫描。
webApp.contextPath 指定web项目的根路径,默认为/。
2.配置connectors修改默认监听端口:
<plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>8.1.16.v20140903</version> <configuration> <scanIntervalSeconds>10</scanIntervalSeconds> <webApp> <contextPath>/test</contextPath> </webApp> <connectors> <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector"> <port>9090</port> <maxIdleTime>60000</maxIdleTime> </connector> </connectors> </configuration> </plugin>
jetty的默认监听端口为8080,可以.配置connectors进行修改,还可以使用命令行参数。
mvn jetty:run -Djetty.port=9999
3.配置访问日志:
<plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>8.1.16.v20140903</version> <configuration> <scanIntervalSeconds>5</scanIntervalSeconds> <webApp> <contextPath>/test</contextPath> </webApp> </configuration> <requestLog implementation="org.eclipse.jetty.server.NCSARequestLog"> <filename>target/access.log</filename> <!--日志路径--> <retainDays>90</retainDays> <!--日志保留天数--> <append>false</append> <!--是否追加--> <extended>false</extended> <!--是否扩展--> <logTimeZone>GMT+8:00</logTimeZone> <!--时区--> </requestLog> </plugin>
4.配置系统属性:
<plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>8.1.16.v20140903</version> <configuration> <scanIntervalSeconds>5</scanIntervalSeconds> <webApp> <contextPath>/test</contextPath> </webApp> </configuration> <systemProperties> <systemProperty> <name>productionMode</name> <value>false</value> </systemProperty> </systemProperties> <!--使用属性文件 --> <systemPropertiesFile>${basedir}/mysys.props</systemPropertiesFile> </plugin>
参考:
http://my.oschina.net/cokolin/blog/409164