前言: 有时我们项目中用到了三方的Jar包,在Maven中心仓库中没有。那这时候我们就要手动把Jar包下载好,然后导入到项目中使用;当然也可以把Jar包上传到自己公司的私服中(本文不考虑此种情况)。
环境
- Maven项目
步骤
1、上传Jar包:在使用Jar包的项目模块下创建lib文件夹,并且把Jar放入;如图
2、配置pom文件: 在当前模块下的pom.xml中添加如下配置:如图:
2-1、添加Jar坐标:
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>14.7.0</version>
<scope>system</scope>
<!-- ${pom.basedir}:此pom.xml文件所在的项目模块路径 -->
<systemPath>${pom.basedir}/lib/aspose-words-15.8.0-jdk16.jar</systemPath>
</dependency>
2-2、添加编译和打包的plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<compilerArguments>
<extdirs>${project.basedir}/lib</extdirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
测试:
编译:mvn compile
打包:mvn package (该Jar包打进了项目.jar的\BOOT-INF\lib目录中);
注意: 项目使用Jenkins打包/部署的也是一样,只要自己本地可以正常编译/打包。