在POM文件中引入第三方jar包
我目前所知的有两种方式可以引入:
1.从本地引入
我的jar包在src/lib下,那么pom文件中引入形式:
1.1
<dependency>
<groupId>CNCBCryptoPkg</groupId>
<artifactId>CNCBCryptoPkg</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/src/lib/CNCBCryptoPkg-1.0.jar</systemPath>
</dependency>
如果是在项目根目录下,则systemPath标签为:
<systemPath>${project.basedir}/src/lib/CNCBCryptoPkg-1.0.jar</systemPath>
1.2 在pom文件的build标签中添加以下:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
</plugins>
</build>
关键代码:
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
上面的dependency标签中各属性都不能缺少,如果没有version可以改变jar自设一个version,比如上面的jar原本为:CNCBCryptoPkg.jar,改名CNCBCryptoPkg-1.0.jar并将version设置为1.0;网上有些作者说可以随便设置,但是打包后jar包名称是根据这里的dependency标签来生成的,不确定是否有影响,但建议设置为一致
2.将第三方jar包加入到maven本地仓库,然后引入
执行mvn命令:
mvn install:install-file -Dfile=D:\projects\xxx\xxx\src\lib\CNCBCryptoPkg-1.0.jar -DgroupId=CNCBCryptoPkg -DartifactId=CNCBCryptoPkg -Dpackaging=jar -Dversion=1.0
成功后即可安装常规的mvn依赖引入,eg:
<dependency>
<groupId>CNCBCryptoPkg</groupId>
<artifactId>CNCBCryptoPkg</artifactId>
<version>1.0</version>
</dependency>
build标签中的也不需要额外添加
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>