设为首页 收藏本站
查看: 710|回复: 0

[经验分享] [使用心得]maven2之m2eclipse使用手册之六使用Maven2插件创建一个简单的SSH2项目之jetty篇(三)

[复制链接]

尚未签到

发表于 2017-2-27 12:28:45 | 显示全部楼层 |阅读模式
  终于到了使用jetty插件的时候,使用jetty非常之简单,对于使用maven-jetty-plugin来说,它有几个命令,这里只是简单介绍了jetty:start与jetty:stop,其使用方法如下:

mvn jetty:run :这个命令故名意思就是启动jetty服务器,以8080的服务端口进行启动,如果你需要关闭其服务器请运行mvn jetty:stop命令,
对于其pom.xml配置如下:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.24</version>
</plugin>
  如果需要使用自动执行的话,请参考官方的pom.xml配置,如下:



<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<stopKey>foo</stopKey>
<stopPort>9999</stopPort>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
  定义<daemon>true</daemon>标签防止永不停止的运行,其运行状态只在maven启动的时候才会运行,这里只是针对maven2的cmd版本,对于m2eclipse来说是不同的
  而<scanIntervalSeconds>0</scanIntervalSeconds>简单来说让当前应用是否使用热插拔功能,默认0是不扫描项目,输入秒数则在多少秒中进行扫描web项目中那些变化了
  如果想定义一组插件组的时候可以在settings.xml中定义以下内容:



<profile>
...
<pluginGroups>
<pluginGroup>org.mortbay.jetty</pluginGroup>
</pluginGroups>
</profile>
  注意:使用这个配置运行的时候,stopPort标签必须是可以在本机自由配置的,如果不这样的话很容易会得到一个已经使用过的maven plugin地址,结果当你在执行maven命令的时候将会出现org.mortbay.jetty.plugin.util.Monitor是会引起堆栈异常,
  其英文原话:
  When running with this configuration, the "stopPort" must be free on the machine you are running on. If this is not the case, you will be getting an "address already in use" from the maven plugin, which appears *after* the "Started SelectedChannelConnector ..." message. If you run with the mvn -X option, you'll see org.mortbay.jetty.plugin.util.Monitor is part of the causing stacktrace.

mvn jetty:stop:停止当前jetty服务器的命令,对于它,也有它的配置项,pom.xml文件如下:


<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
<configuration>
<stopPort>9966</stopPort>
<stopKey>foo</stopKey>
</configuration>
</plugin>
  一般来说运行使用了jetty:run,jetty:run-war,jetty:run-exploded 这些命令可以通过窗口的按钮停止服务器启动,如果需要mvn jetty:stop命令的话则需要配置特殊的端口去进行停止,
  英文原话:
  The run, run-war and run-exploded goals leave the plugin running indefinitely. You can terminate it with a <cntrl-c> in the controlling terminal window, or by executing the stop goal in another terminal window. If you wish to be able to use mvn jetty:stop then you need to configure the plugin with a special port number and key that you also supply on the stop command.
对于maven-jetty-plugin,还有其他命令分别是:

jetty:run:在webapp没进行部署的时候可以通过一些配置参数进行运行,

jetty:run-war:通过<configuration>标签指定webapp位置进行运行该以war形式的wepapp

jetty:run-exploded:讲目标项目组装成一个文件,然后检查<scanInterval>标签是否为0,如果不为0,jetty会检查你的pom.xml文件,必要的时候将会重新部署web.xml

jetty:deploy-war:使用maven中的 package命令打成war包,然后部署到jetty中
  更加详细的详细,可以参考一下网址:

Maven Jetty Plugin Configuration Guide



介绍了那么多了,都是基于maven下的,到了m2eclipse我们怎么运行其命令呢?
  答案是很简单的,在maven project中run as中选择build.. 选项(如图1:选择),出现一个命令框,在Goals输入jetty:start(如图2:输入命令),单击run,然后查看Console中的内容(实际中每个系统都不同的信息),你将会看到maven已经进行了build和部署了,默认使用了jetty:run的命令(如图:3运行信息),最终运行成功后会提示[INFO] Started Jetty Server这个信息(如图4:正常运行),红字那些则是配置框架时候那些信息.运行http://localhost:8080/SSH2Maven/index.jsp(如图5:页面信息),会出现正常的页面了,而后台也会出现查询数据的sql语句(如图6:后台打印信息).
[img]http://onexin.iyunv.com/source/plugin/onexin_bigdata/https://uoyzvw.blu.livefilestore.com/y1mg_jkSo6EfZvpmvO6OQy-NQcbr5pl-Lr6apsHACWi2dvCAXLVT0gpWzD-98cDXlW-4xuSWgrvZDHYhBPbmIL0f6Fa9b0yBEs8oLIRIWalY1NsEvMjK4zLjrQBFIgkxQr6J2OZFATnSPWL6pNGpnjICA/image_thumb[2][/img] 图1:选择

[img]http://onexin.iyunv.com/source/plugin/onexin_bigdata/https://uoyzvw.blu.livefilestore.com/y1mbWhq9-rJnQMG404M8hiYoGvL0RQbj3rjAb1Q5UrkLUV9lu2yHWxhzWIJn8LUTmehG_qjDCXf2xMqZIfu4qjAC6nLd2LQMz0l0_mx0Pvoi4Z0FrMsw6WraPcWDR95lnGBoLxzw65f3cVTCdc4Ld3KPg/image_thumb[10][/img] 图2:输入命令


[img]http://onexin.iyunv.com/source/plugin/onexin_bigdata/https://uoyzvw.blu.livefilestore.com/y1mtpsgan9hxaJnx-b0zvH4UWNcUPHSz18Ccz66CGVl2oa0NGHKsamPx3SOKh4H0vM6f1x63JQ7sspwFIEpopfMZmrbZYia3ain6qI2uEJ5eILOwAR5_UWioRprVPpkZOXx1OwwdZizqDMYTykkzjzxQA/image_thumb[14][/img] 图:3运行信息
[img]http://onexin.iyunv.com/source/plugin/onexin_bigdata/https://uoyzvw.blu.livefilestore.com/y1mNRu9P07j7H1r4N01-QzERYAigIw_WeiaQjN4fTp4E6uRIDTpr1LMIkKsI7D33J9oFcEP3a7Yg6F1ebdRaaxe55fxRJO0lnr7tgtZUsjgj6N3fYHjeKEUUNTxzzQw8bb41NsCEa_b2Caa1jqeMU6Llw/image_thumb[18].png?download&psid=1[/img] 图4:正常运行

[img]http://onexin.iyunv.com/source/plugin/onexin_bigdata/https://uoyzvw.blu.livefilestore.com/y1mfH45jFsbuvoaGQRaKe9DOG8gp3P527YRKWS_YpcKDqk10MPdQ2_TG9C3CURr6D9eupwWhwKgON9vXRCsJhX6gcJ64jQupu5tZPbBXlrmmLHE9PHKT-mpwQg5VJ4WkHUUzsIWh3ndBClfzacYiuFVzg/image_thumb[20][/img] 图5:页面信息

[img]http://onexin.iyunv.com/source/plugin/onexin_bigdata/https://uoyzvw.blu.livefilestore.com/y1mL3lgg8hr-MJFw7n0AI9rCHrGxV6agI9UqZ9tssznkgaj6hD4f_9y_7FdvJMehFO1xmAwsbvQ7LGoKNEIAcQtju3BvrE8a1Gy9m2pmmM46uI4K4PZU0PPVULUa9UOC9WaK9Q2isxXYr8unmEEnqs1vA/image_thumb[22][/img]图6:后台打印信息

  注意:使用strut2中的<s:debug/>标签的时候如果你删除了后再刷新,再添加<s:debug/>标签的话会出现异常,这个异常估计是跟jetty的热部署有关系,所以如果使用了<s:debug/>这个标签的话千万就不要随意删除了,否则很容易引起不必要的错误.
  补充:默认jetty默认是jsp2.1,如果需要使用jsp2.0的话则可以使用以下配置



<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.14</version>
<dependencies>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jsp-api-2.0</artifactId>
<version>6.1.14</version>
</dependency>
<dependency>
<groupId>tomcat</groupId>
<artifactId>jasper-compiler-jdt</artifactId>
<version>5.5.15</version>
</dependency>
<dependency>
<groupId>tomcat</groupId>
<artifactId>jasper-compiler</artifactId>
<version>5.5.15</version>
</dependency>
<dependency>
<groupId>tomcat</groupId>
<artifactId>jasper-runtime</artifactId>
<version>5.5.15</version>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jsp-2.1</artifactId>
<version>6.1.14</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jsp-api-2.1</artifactId>
</exclusion>
<exclusion>
<groupId>org.mortbay.jetty</groupId>
<artifactId>start</artifactId>
</exclusion>
<exclusion>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-annotations</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
....
</plugin>

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-347992-1-1.html 上篇帖子: Java使用Jetty实现嵌入式Web服务器及Servlet容器 下篇帖子: Jetty Cross Origin Filter解决jQuery Ajax跨域访问的方法
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表