步骤1: 正常编译JAR包,解压出lib文件夹
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <!--<version>2.3.5.RELEASE</version>--> <configuration> <mainClass>org.joe.SystemApplication</mainClass> <layout>ZIP</layout> <!--<includes> <include> <groupId>nothing</groupId> <artifactId>nothing</artifactId> </include> </includes>--> </configuration> </plugin> </plugins> </build>
- 打包命令:mvn clean install
- 将Jar包解压,拷贝 BOOT-INF 目录下的lib文件夹 到目标路径;
步骤2: 编译打包不带 lib 文件夹的Jar包
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <!--<version>2.3.5.RELEASE</version>--> <configuration> <mainClass>org.joe.SystemApplication</mainClass> <layout>ZIP</layout> <!--打包不带 lib 文件夹的Jar包--> <includes> <include> <groupId>nothing</groupId> <artifactId>nothing</artifactId> </include> </includes> </configuration> </plugin> </plugins> </build>
- 打包:mvn clean install
步骤3: 运行编译后的Jar包
#-Dloader.path=lib文件夹路径 # 相对路径 java -Dloader.path=./lib -jar test123.jar # 绝对路径 java -Dloader.path=/app/path/lib -jar test123.jar