场景:SpringBoot Starter 打包一直失败,尝试网上若干方法后,不见成功。
原因:pom.xml 继承了 SpringBoot Parent ,因此每次打包都是可执行的包,然后 stater 没有主类打包失败。
解决方案:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<!-- 加入这个不用加 SpringBoot-parent 依赖,也可以管理依赖 -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${springboot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
第一个坑解决了,第二个坑聚合工程必须 install 的坑,根据提示 install
第三个坑,项目打包后启动无法发现主类清单
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!-- 防止主清单为空 -->
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
</build>
下载后放入对应的 jre 文件下
链接: https://pan.baidu.com/s/1Nmd-AXzVC0fICNqGEHePFw 提取码: kbk5
-XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly