1、全量打包
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!--需注意使用JDK版本号,否则会报版本编译错误 -->
<version>2.7.17</version>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
<!--idea打jar包,提示 jar包中没有主清单属性 - 解决办法 <goal>repackage</goal>起了作用,内容如下:-->
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
版本不对导致错误信息:
org/springframework/boot/maven/RepackageMojo has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0
解决办法:将spring-boot-maven-plugin版本调整对JDK对应的版本即可
对应表:
52 = Java 8
53 = Java 9
54 = Java 10
55 = Java 11
56 = Java 12
57 = Java 13
58 = Java 14
2、瘦身打包:将jar包与lib 依赖和resource 配置文件分离
更新时,只需更新jar即可
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<!-- 排除配置文件 -->
<excludes>
<exclude>*.properties</exclude>
<exclude>*.yml</exclude>
<exclude>*/*.properties</exclude>
<exclude>*/*.yml</exclude>
</excludes>
<archive>
<manifest>
<!-- 是否要把第三方jar加入到类构建路径 -->
<addClasspath>true</addClasspath>
<!-- 依赖jar包的位置 -->
<classpathPrefix>lib/</classpathPrefix>
<!--指定main主程序入口-->
<mainClass>com.zz.MainApplication</mainClass>
</manifest>
<manifestEntries>
<!--MANIFEST.MF 中 Class-Path 加入自定义路径,多个路径用空格隔开, 加入resource资源访问路径-->
<!-- resources文件夹的内容,需要maven-resources-plugin插件补充上-->
<Class-Path>./resources/</Class-Path>
<!--引入第三方包,加入lib/XXX-1.0.jar lib/YY-1.0.jar 注意需要有空格,
如果不想这样加入第三方包的引用,就直接将第三方包打包到本地仓库,然后dependency依赖 -->
<!-- <Class-Path>./resources/lib/XXX-1.0.jar lib/YY-1.0.jar</Class-Path> -->
</manifestEntries>
</archive>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<!-- 拷贝依赖包到lib/目录下 -->
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<!-- 复制配置文件到resources -->
<execution>
<id>copy-resources</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<outputDirectory>${project.build.directory}/resources/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>