SpringBoot复习:Maven打包发布项目

当前springboot版本:2.1.18.RELEASE

1.声明

当前内容主要用于本人复习springboot项目,中使用maven打包的过程,以及其中出现的各种问题!

eclipse中使用maven build,必须配置好maven猜可以使用
在这里插入图片描述

2.问题1:maven build问题(No goals have been specified for this build. )

No goals have been specified for this build. 
You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. 
Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources,
 process-resources, compile, process-classes, generate-test-sources, process-test-sources,
  generate-test-resources, process-test-resources, test-compile, process-test-classes, test, 
  prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify,
   install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]

在这里插入图片描述

一看,这个么多错误实际就是这个问题:缺少goal

解决办法:在当前的pom.xml文件中添加下列

<build>
	<defaultGoal>compile</defaultGoal>
	<plugins>
		<plugin>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-maven-plugin</artifactId>
		</plugin>
	</plugins>

</build>

主要问题是这个<defaultGoal>compile</defaultGoal>没加导致的

更正后:
在这里插入图片描述

此时是maven编译成功,并不是打包成功,只是生产了对应的maven信息

在这里插入图片描述

问题2:maven打包问题

首先使用cmd方式切到当前的项目的pom位置:使用mvn package执行打包命令

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.1.18.RELEASE:repackage (repackage) on project spring-boot-restart: Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:2.1.18.RELEASE:repackage failed: Unable to find a single main class from the following candidates [com.hy.springboot.restudy.App, com.hy.springboot.restudy.Example] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

此时报错,原因:当前包中不知一个具有main方法的入口类,也就是说有如果有多个入口类那么打包是不成功的!

对应操作:删除除了SpringBoot之外的main方法入口类

清空当前的在eclipse中执行maven clean然后再次build后再使用命令行执行package结果为:

在这里插入图片描述

此时maven打包成功,成功出现一个jar文件,这个文件就是可以使用java命令执行的文件,并且这个jar包中有10多M大小

3.执行springboot的jar包

1.切换到执行的jar包的路径中执行:java -jar spring-boot-restart-0.0.1-SNAPSHOT.jar
在这里插入图片描述

浏览器访问后:
在这里插入图片描述

访问成功!

或者直接打包:<defaultGoal>package</defaultGoal>,那么此时使用eclipse执行run–>maven build的时候就会直接达成包(也可以是repackage)

4.总结

1.使用maven build的时候小心错误,有的时候错误太多现实也不好解决,需要理解

2.maven中的mvn package只能打具有一个main方法的maven项目

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值