1、创建maven的web项目
具体看上一篇博客的内容
2、加入servlet-api的jar文件
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5.20110712</version>
<scope>provided</scope>
</dependency>
3、加入jetty的插件
<build>
<finalName>user-web</finalName>
<plugins>
<plugin>
<!--没有写版本,会自动下载一个最合适的版本 -->
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<webApp>
<!--修改项目的访问名称为 hello-->
<contextPath>/hello</contextPath>
</webApp>
<!-- 修改端口 -->
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>8787</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
</configuration>
</plugin>
</plugins>
</build>
4、运行命令
clean compile jetty:run