我們可以在Springboot框架中使用Maven插件來管理我們的依賴淋叶。
1撼泛、正常打包
會將所有的依賴一起打入jar包
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
2茫船、依賴和代碼分離
<plugins>
<!--配置是否依賴分離-->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<layout>ZIP</layout>
<!-- 注釋后和依賴包一起打包 取消注釋則不打包依賴-->
<includes>
<include>
<groupId>nothing</groupId>
<artifactId>nothing</artifactId>
</include>
</includes>
</configuration>
</plugin>
<!--指定啟動類-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.zl.Application</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<!--復(fù)制依賴到target/lib文件夾-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-lib</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>target/lib</outputDirectory>
<excludeTransitive>false</excludeTransitive>
<stripVersion>false</stripVersion>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
3近速、集成第三方包
將第三方包放到項目根目錄的lib文件夾下
<dependencies>
<!-- 用systemPath指定第三方包的路徑 -->
<dependency>
<groupId>com.zl</groupId>
<artifactId>com.zl</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/sapjco.jar</systemPath>
</dependency>
</dependencies>
<build>
<resources>
<!-- 加入如下配置,把jar包以資源形式打包進指定路徑 -->
<resource>
<directory>${project.basedir}/lib</directory>
<targetPath>BOOT-INF/lib/</targetPath>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<targetPath>BOOT-INF/classes/</targetPath>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.5.7</version>
</plugin>
</plugins>
</build>