做WEB開發,測試是一件很費時間的事情。所以我們就應該用更簡單、更快捷的方式進行測試。今天就向大家介紹一個輕量級的容器——jetty。j今天說的etty是Maven的一個外掛程式jetty-maven-plugin,與Maven配合起來使用非常的方便,它的配置也非常的簡單,下面我們就看看它怎麼用吧!
在pom.xml 檔案的<project>標籤下加入如下代碼:
<build><plugins><plugin><groupId>org.mortbay.jetty</groupId><artifactId>jetty-maven-plugin</artifactId><version>8.1.10.v20130312</version><configuration><connectors><connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector"><port>8888</port></connector></connectors><webAppSourceDirectory>${basedir}/WebContent</webAppSourceDirectory><scanIntervalSeconds>10</scanIntervalSeconds><webAppConfig><contextPath>/${project.artifactId}</contextPath></webAppConfig></configuration></plugin></plugins></build>
這樣配置就算完成了,然後在pom.xml檔案上右擊,指向Run As,選擇Maven build,在彈出的視窗的“Goals”中輸入“jetty:run”,然後點擊“run”。
當出現如下資訊代表jetty啟動成功:
[INFO] Started Jetty Server
[INFO] Starting scanner at interval of 10 seconds.
OK,怎麼樣?很簡單吧,動手試試吧!