0
点赞
收藏
分享

微信扫一扫

使用Maven为SpringBoot项目打包

小磊z 2023-03-13 阅读 77


一、maven通过命令行打jar包

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



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 goal org.springframework.boot:spring-boot-maven-plugin:2.1.4.RELEASE:repackage failed: Unable to find main class



使用Maven为SpringBoot项目打包_maven


解决办法:

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



使用Maven为SpringBoot项目打包_jar_02


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



使用Maven为SpringBoot项目打包_maven_03


打包成功!

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


java -jar web-0.0.1-SNAPSHOT.jar




使用Maven为SpringBoot项目打包_vue_04


 二、maven通过命令行打war包

修改代码如下



使用Maven为SpringBoot项目打包_jar_05


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


mvn -Dmaven.test.skip -U clean package


发现报如下错误:

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



使用Maven为SpringBoot项目打包_maven_06


解决办法:

新增如下代码结构



使用Maven为SpringBoot项目打包_maven_07


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



使用Maven为SpringBoot项目打包_vue_08


打包成功!

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



使用Maven为SpringBoot项目打包_maven_09


举报

相关推荐

0 条评论