maven jetty 插件的使用
jetty插件的安裝
首先打開項(xiàng)目的pom.xml文件,然后找到build節(jié)點(diǎn),在其中添加plugins節(jié)點(diǎn),然后再添加如下的插件:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.3.7.v20160115</version>
</plugin>
然后重新編譯一下,就可以使用jetty插件了。使用mvn jetty:run就可以運(yùn)行maven項(xiàng)目了。當(dāng)前9.3.7是最新的jetty版本,以后會(huì)有更新的,請隨時(shí)修改jetty的版本。
jetty插件的配置
在pom.xml中配置
在plugin節(jié)點(diǎn)下,添加configuration節(jié)點(diǎn)就可以配置jetty插件了。
<configuration>
<httpConnector>
<port>8080</port>
<host>localhost</host>
</httpConnector>
<scanIntervalSeconds>1</scanIntervalSeconds>
</configuration>
idleTimeout。一次連接的最大空閑時(shí)間。
port。jetty服務(wù)器的端口號。
host。jetty服務(wù)器監(jiān)聽的地址。
scanIntervalSeconds。掃描進(jìn)行熱部署的間隔時(shí)間。
*
在jetty配置文件中配置
jetty插件也支持將jetty配置到相應(yīng)的配置文件中,然后在pom.xml中引用這些配置文件。就像這樣:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.3.7.v20160115</version>
<configuration>
<jettyXml>jetty.xml,jetty-ssl.xml,jetty-https.xml</jettyXml>
</configuration>
</plugin>
jetty插件的運(yùn)行
jetty:run
jetty:run命令會(huì)直接使用源代碼運(yùn)行web程序,不將其打包成war文件。jetty插件會(huì)保證在運(yùn)行前所有的類和資源都是最新的。如果你修改了代碼,插件會(huì)自動(dòng)重新部署。
jetty:run-war
run-war會(huì)先將程序打包成war文件然后再將其部署。如果有代碼修改,會(huì)重新打包war文件并部署。
|