进入项目目录,执行如下命令:

mvn -Dmaven.test.skip -U clean package

发现报如下错误:

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin
:2.1.4.RELEASE:repackage (repackage) on project model: Execution repackage of go
al org.springframework.boot:spring-boot-maven-plugin:2.1.4.RELEASE:repackage fai
led: Unable to find main class

使用Maven为SpringBoot项目打包

解决办法:

新增如下代码,并将代码移到主工程目录下:

使用Maven为SpringBoot项目打包

继续执行上面的打包命令:

使用Maven为SpringBoot项目打包

打包成功!

进入生成的jar目录中,运行jar文件:

java -jar web-0.0.1-SNAPSHOT.jar

使用Maven为SpringBoot项目打包

 二、maven通过命令行打war包

修改代码如下

使用Maven为SpringBoot项目打包

进入项目目录,执行如下命令:

mvn -Dmaven.test.skip -U clean package

发现报如下错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:3.2.2:w
ar (default-war) on project web: Error assembling WAR: webxml attribute is requi
red (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]
[ERROR]

使用Maven为SpringBoot项目打包

解决办法:

新增如下代码结构

使用Maven为SpringBoot项目打包

继续执行上面的打包命令:

使用Maven为SpringBoot项目打包

打包成功!

进入生成的war目录中,运行war文件:

使用Maven为SpringBoot项目打包

相关文章:

  • 2021-12-17
  • 2021-04-19
  • 2021-04-13
  • 2021-06-15
  • 2021-08-27
  • 2022-12-23
  • 2022-12-23
  • 2021-08-16
猜你喜欢
  • 2022-12-23
  • 2021-06-23
  • 2021-11-30
  • 2022-12-23
  • 2021-11-12
  • 2022-12-23
相关资源
相似解决方案