1 jetty-maven-plugin
1.1 pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>Demo</artifactId>
<groupId>me.jtzen9</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>demo-jetty</artifactId>
<packaging>war</packaging>
<name>demo-jetty Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<jetty.maven.plugin.version>9.4.7.v20170914</jetty.maven.plugin.version>
</properties>
<build>
<finalName>demo-jetty</finalName>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.maven.plugin.version}</version>
<configuration>
<httpConnector>
<!-- 服务器端口号 -->
<port>8888</port>
<!-- Maximum idle time for a connection -->
<idleTimeout>60000</idleTimeout>
</httpConnector>
<!--<jettyXml>src/main/resources/jetty-env.xml</jettyXml>-->
<!-- 自动扫描文件改变并进行热部署的时间间隔,默认值0,代表着禁用扫描并热部署. -->
<scanIntervalSeconds>2</scanIntervalSeconds>
<reload>automatic</reload>
<!-- 可选择的配置,默认false,启动时是否打印出server的结构。 -->
<dumpOnStart>false</dumpOnStart>
<!-- 请求log -->
<requestLog implementation="org.eclipse.jetty.server.NCSARequestLog">
<!-- log输出目录-->
<filename>target/yyyy_mm_dd.request.log</filename>
<!--<filenameDateformat>yyyy_MM_dd</filenameDateformat>-->
<!-- log保存天数-->
<retainDays>90</retainDays>
<!-- log是否附加在文件后-->
<append>true</append>
<extended>false</extended>
<!-- 时区-->
<logTimeZone>GMT+8:00</logTimeZone>
</requestLog>
<stopPort>9966</stopPort>
<stopKey>jtzen9</stopKey>
<stopWait>10</stopWait>
<webAppSourceDirectory>src/main/webapp</webAppSourceDirectory>
<webApp>
<!-- 项目根目录 -->
<contextPath>/demo-jetty</contextPath>
<!-- 当前web应用的web.xml路径 -->
<!--<descriptor></descriptor>-->
</webApp>
</configuration>
</plugin>
</plugins>
</build>
</project>
1.2 src/main/resources/jetty-env.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">
<!-- 应用数据源 -->
<New id="showcase" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg>jdbc/showcase</Arg>
<Arg>
<New class="org.apache.commons.dbcp.BasicDataSource">
<Set name="driverClassName">oracle.jdbc.driver.OracleDriver</Set>
<Set name="url">jdbc:oracle:thin:@127.0.0.1:1521/orcl</Set>
<Set name="username">scott</Set>
<Set name="password">scott</Set>
<Set name="maxActive">10</Set>
</New>
</Arg>
</New>
</Configure>
1.3 启动
运行时候只要maven build->输入jetty:run即可