Maven - jetty 运行与调试

本文介绍如何使用Maven和Jetty插件实现web项目的热部署,详细配置包括插件安装、运行命令及参数说明,如scanIntervalSeconds等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用Maven发布web项目,一般使用JETTY容器,因为tomcat不能热部署,必须打包然后发布,增加工作量,而jetty可以热部署。

1、Maven插件安装

<plugin>
					<groupId>org.eclipse.jetty</groupId>
					<artifactId>jetty-maven-plugin</artifactId>
					<version>9.3.7.v20160115</version>
					<configuration>
						<scanIntervalSeconds>10</scanIntervalSeconds>
						<webApp>
							<contextPath>/account</contextPath>
						</webApp>
						<httpConnector>
							<port>8787</port>
						</httpConnector>
					</configuration>
				</plugin>

然后重新编译一下,就可以使用jetty插件了。使用mvn jetty:run就可以运行maven项目了。
注意:如果是聚合形式项目,jetty一般配置再parent pom pluginManagement 中,子类web项目需要声明继承关系,另外 因为子类继承parent jetty的配置,如有更改建议重新编译打包,未避免打包,可以将具体configuration放到子pom中,只重新编译子项目即可。

scanIntervalSeconds。扫描进行热部署的间隔时间。

jetty插件的运行
jetty:run
jetty:run命令会直接使用源代码运行web程序,不将其打包成war文件。jetty插件会保证在运行前所有的类和资源都是最新的。如果你修改了代码,插件会自动重新部署。

The run goal runs on a webapp that does not have to be built into a WAR. Instead, Jetty deploys the webapp from its sources. It looks for the constituent parts of a webapp in the Maven default project locations, although you can override these in the plugin configuration. For example, by default it looks for:

resources in ${project.basedir}/src/main/webapp
classes in ${project.build.outputDirectory}
web.xml in ${project.basedir}/src/main/webapp/WEB-INF/
The plugin automatically ensures the classes are rebuilt and up-to-date before deployment. If you change the source of a class and your IDE automatically compiles it in the background, the plugin picks up the changed class.

jetty:run-war

run-war会先将程序打包成war文件然后再将其部署。如果有代码修改,会重新打包war文件并部署。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值