且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

spring-boot Maven:如何使用主类创建可执行 jar?

更新时间:2022-05-17 00:05:58

为什么我必须添加 spring-boot-maven-plugin?我已经有了 spring-boot-starter-web 依赖项,将 spring-boot 添加为依赖项,以及 maven-compiler-plugin 从代码构建 jar 文件?

Why must I add spring-boot-maven-plugin? I already have spring-boot-starter-web dependency that adds spring-boot as a dependency and maven-compiler-plugin that builds a jar file from the code?

因为该插件为 Spring Boot 添加了 Maven 支持

Because the plugin is what adds Maven support for Spring Boot

你能想出一种配置 pom.xml 文件的方法吗,我将能够使用native"命令mvn clean package"而不是繁琐的mvn clean package spring-boot:repackage"来获取 jar 文件?

Can you think about a way to configure pom.xml file that I'll be able to get the jar file using the "native" command "mvn clean package" and not the cumbersome "mvn clean package spring-boot:repackage"?

您似乎缺少 jar</packaging> 元素之间的 </project> 元素.

It looks like you are missing the <packaging>jar</packaging> element in between your <project> </project> element.

您必须运行那个冗长命令的原因,是因为您在包含插件时没有包含 </executions> 元素.请参阅以下文档的第 71.1 节:

The reason you had to run that lengthy command, is because you did not include the <executions></executions> element when including the plugin. Please see section 71.1 of the following docs:

https://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-maven-plugin.html#build-tool-plugins-include-maven-plugin

71.2 详细说明了 元素.

71.2 elaborates on the <packaging> element.