前言
- springboot 2.0.0.RELEASE
- maven 3.5.0
使用maven命令mvn package
打包spring boot项目时,将lib分离出来。
pom.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<build>
...
<plugins>
<!-- lib分离打包步骤 : 1,copy-dependencies -> 2,repackage -->
<!-- lib分离打包1/2 copy-dependencies : 拷贝依赖文件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/final-package/lib/
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<!-- lib分离打包2/2 repackage : spring boot 打包设置,不打包lib -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<includes>
<!--不将依赖的jar打包到spring boot的jar/war中 -->
<include>
<groupId>null</groupId>
<artifactId>null</artifactId>
</include>
</includes>
<layout>ZIP</layout>
<!--设置spring boot的jar/war的存放路径 -->
<outputDirectory>${project.build.directory}/final-package</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>
打包命令
mvn clean package
启动命令
java -Dloader.path=lib -jar xxx-springboot-app.jar