一、描述
将 spring boot 项目打包后,执行java -jar,报如下错误:xxx.jar中没有主清单属性
二、分析
原本项目是基于spring的,目前将项目重构成基于spring boot,由于已存在<parent>,故没有使用<parent>标签引入spring boot 主依赖。而是使用的<dependencyManagement>标签
引入spring boot 主依赖
使用 spring boot 插件来构建项目
发现:
1.spring-boot-maven-plugin 没有依赖进来【鼠标放上去,按ctrl键,点不进去】
2.项目打包后,打包的结构不是 spring boot 项目的结构【本项目打包结构】
三、 解决方案
将 pom.xml 中修改如下
重新打包,spring boot 项目结构正确
打开META-INF/MANIFEST.MF,可以看到 spring boot 主程序:
再次执行 java -jar,正常启动