1. 程式人生 > >Spring boot maven 打包本地 Jar

Spring boot maven 打包本地 Jar

因為需要用到騰訊雲的一些服務,所以得使用騰訊雲的加密工具的 jar。但是這些 jar 只能通過本地進行引用、打包、部署。

首先說,我的專案是 maven 分模組的,某一個子模組需要用到這些本地 jar。

我使用的是 Spring-boot-plugin 3.7.0 。

子模組的 pom.xml 顯示:

<build>
	<plugins>
		<plugin>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-maven-plugin</artifactId>
			<configuration>
				<includeSystemScope>true</includeSystemScope>
			</configuration>
		</plugin>
	</plugins>
</build>

下面是我的本地 jar 包匯入操作:

1. 在需要使用的模組下建一個 lib 資料夾,然後然後將本地 jar 放進去

2. 通過下面的 maven dependency 匯入

<dependency>
	<groupId>gson-2.3.1</groupId>
	<artifactId>gson-2.3.1</artifactId>
	<version>1.0</version>
	<scope>system</scope>
	<systemPath>
		${basedir}/lib/gson-2.3.1.jar
	</systemPath>
</dependency>

groupId 和 artifactId 可以根據 jar 包名來寫。然後 <scope> 寫的是 system。系統路徑的使用 ${basedir} 來確定決定路徑。(看到網上有些文章是使用 ${project.baseUrl} ,但是我試了不成功。)

 

總結一下步驟:

1. 開特定的資料夾,讓 maven 能夠找到 jar

2. 使用 maven 找到本地 jar 包,並進行解析和匯入