0330课堂学习通过 XML来对Jetty进行配置
准备工作:
打开IDRA软件
在自己的分支下pull远程代码更新分支
开始任务:
3个web容器:Tomcat、jetty、undertow(本次使用的是jetty)
- 进入mvnrepository.com搜索jetty-maven-plugin (jetty插件)点击进入,如果要用Tomcat则搜索tomcat进入
- 由于我建的是maven工程这里复制了maven下的插件代码
- 在idea中打开pom.xml(Maven项目构建文件)粘贴成如图所示,作为插件使用
暂未添加配置信息,此时先做运行配置设置
-
点击+号选择maven,根据图上操作配置后 点击OK
-
开始运行
-
运行成功:
-
接着在第3步后面添加配置信息
<plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>8.1.16.v20140903</version> <configuration> <webApp> <contextPath>/</contextPath> </webApp> <stopKey>webx</stopKey> <stopPort>9999</stopPort> <connectors> <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector"> <port>8081</port> <maxIdleTime>60000</maxIdleTime> </connector> </connectors> <requestLog implementation="org.eclipse.jetty.server.NCSARequestLog"> <filename>target/access.log</filename> <retainDays>90</retainDays> <append>false</append> <extended>false</extended> <logTimeZone>GMT+8:00</logTimeZone> </requestLog> </configuration> </plugin>
完成后点击运行,参照第5步,在浏览器上输入地址http://localhost:8081
结束工作:
提交代码 push更新远程分支
jetty与Tomcat比较,jetty相比Tomcat更加轻量级,满足共有云的分布式环境的需求,而Tomcat更符合企业级环境。