在項目中為了友善起見需要把伺服器內建到Maven中以友善調試,

作為plugin內建:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<webAppConfig>
<contextPath>/web</contextPath>
<!-- 額外的ClassPath配置,路N多的properties檔案等 -->
<extraClasspath>properties</extraClasspath>
</webAppConfig>
<contextHandlers>
<!-- 子項目依賴,或者需要加多個項目到這一個jetty運作環境裡面 -->
<contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext">
<war>../subweb/src/main/webapp</war>
<contextPath>/subweb</contextPath>
</contextHandler>
</contextHandlers>
<systemProperties>
<systemProperty>
<name>catalina.base</name>
<value>${basedir}/target</>
</systemProperty>
</systemProperties>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>8080</port>
<maxIdleTime>400000</maxIdleTime>
</connector>
</connectors>
</configuration>
</plugin>
直接在項目下運作mvn jetty:run
作為Maven參數內建:
<profiles>
<profile>
<id>run-jetty</id>
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<webAppConfig>
<contextPath>/web</contextPath>
<extraClasspath>properties</extraClasspath>
</webAppConfig>
<contextHandlers>
<contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext">
<war>../subweb/src/main/webapp</war>
<contextPath>/subweb</contextPath>
</contextHandler>
</contextHandlers>
<systemProperties>
<systemProperty>
<name>catalina.base</name>
<value>${basedir}/target</>
</systemProperty>
</systemProperties>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>8080</port>
<maxIdleTime>400000</maxIdleTime>
</connector>
</connectors>
</configuration>
</plugin>
</plugins>
</build>
<profile>
<profiles>
項目下運作 mvn -DskipTests=true clean test -Prun-jetty
http://www.devhup.com/?p=140