项目中有些jar包是第三方的,maven官方仓库没有,
需要使用mvn install命令打包到本地,然后将其写入到pom.xml的依赖中,
maven仓库有的jar包则从maven官网找到对应版本的depdency写入pom文件里面,这样maven打包就可以包含第三方jar包了,否则maven只会打包pom文件里面的,不会包括第三方jar包,程序运行将报错。这里推荐2种打包第三方jar包的方式:
第一种:打包第三方jar包到本地仓库,然后在pom.xml中引入
例如:将alipay-sdk-abc.jar 打包到本地仓库
mvn命令:
mvn install:install-file -Dfile=G:\thirdpartyjar\alipay-sdk-abc.jar -DgroupId=com.thirdparty -DartifactId=alipay-sdk-abc -Dversion=3.1.0.8 -Dpackaging=jar
pom.xml配置:
<dependency>
<groupId>com.thirdparty</groupId>
<artifactId>alipay-sdk-abc</artifactId>
<version>3.1.0.8</version>
</dependency>
第二种:通过在pom.xml中指定第三方jar包路径来引入依赖
比如第三方jar包在lib文件夹下,对pom.xml的配置如下:
<dependencies>标签里面引入第三方jar包的依赖
pom.basedir指的是pom文件所在的目录,
systemPath指的是第三方jar包所在路径。
<dependency>
<groupId>com.abc</groupId>
<artifactId>cryptokit</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${pom.basedir}/lib/cryptokit-1.0.jar</systemPath>
</dependency>
还必须修改<plugins>标签里面的maven plugin,增加includeSystemScope属性并设置为true
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
第二种方式相比第一种方式,省事、方便。