jetty-maven-plugin的插件使用总结
1. 功能描述
Jetty Run a Jetty container for rapid webapp development.
即用于部署web应用
2. 依赖
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.44.v20210927</version>
<type>maven-plugin</type>
</dependency>
其他版本: 所有版本
3. 常用goals
3.1 jetty:deploy-war
部署现成的war包, 默认war包位置:
${project.build.directory}/${project.build.finalName}.war
3.2 jetty:run-war
1.不需要现成的war
2.执行前会执行"package", 会执行default周期package及之前的所有流程
3.热部署: war或project内容有变动后会自动redeploy
3.3 jetty:run
1.不需要现成的war包, test阶段执行
2.并行快速构建, 启动快
3.会先执行clean周期和default周期的compile
4.基于compile的excluded目录直接部署, 不需要打成war包
5.热部署: project内容有变动后会自动redeploy
7.如果有静态资源, 通过webAppSourceDirectory属性配置目录
webAppSourceDirectory (Default: ${maven.war.src})
Root directory for all html/jsp etc files
4. 所有goals
- jetty:deploy-war
- jetty:effective-web-xml
- jetty:help
- jetty:run
- jetty:run-distro
- jetty:run-exploded
- jetty:run-forked
- jetty:run-war
- jetty:start
- jetty:stop
每个goal的具体使用说明, 运行:
mvn help:describe -Dplugin=org.eclipse.jetty:jetty-maven-plugin:9.4.44.v20210927 -Ddetail
5. 常见问题Q&A
- 默认war包位置
默认war包位置: ${project.build.directory}/${project.build.finalName}.war
- 修改jetty运行端口号
启动时加上-Djetty.port=8181
- deploy-war时指定部署war包的位置
默认位置: ${project.build.directory}/${project.build.finalName}.war
通过war配置选项配置
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
<configuration>
<war>/Users/jetty/wars/test-jetty.war</war>
</configuration>
</plugin>
- 跳过jetty插件goal的执行
通过在pom.xml中配置skip为true, 或启动时直接加上 -Djetty.skip
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>