在使用maven进行打包项目中,想要将第三方的jar包放入,有两种方法:一种将jar包上传到maven库中,第二种再pom.xml中进行配置,具体如下:
第一种:安装第三方jar包到maven库
1. 安装maven
1、下载mvn到本地,解压。
2、新建系统变量MAVEN_HOME,值指向安装目录如D:\apache-maven-3.3.9
3、path变量中增加:%MAVEN_HOME%\bin;
4、在MAVEN_HOME/conf/setting.xml中的<localRepository>标签可修改仓库位置(默认位置在C盘的用户下),如<localRepository>E:\Maven\home\repository</localRepository>
5、验证,cmd下输入命令查看安装是否成功(需要先安装好JDK):mvn -version
2. 安装本地jar到仓库
安装命令:
mvn install:install-file -Dfile=jar包的位置 -DgroupId=上面的groupId -DartifactId=上面的artifactId -Dversion=上面的version -Dpackaging=jar
例如:
mvn install:install-file -Dfile=D:\lib\axis.jar -DgroupId=axis -DartifactId=axis -Dversion=1.4.17 -Dpackaging=jar
mvn install:install-file -Dfile=D:\lib\jaxrpc.jar -DgroupId=axis -DartifactId=jaxrpc -Dversion=1.4.17-Dpackaging=jar
将文件打到本地仓中(E:\Maven\home\repository路径下多出axis文件夹,同时多出上面两个jar包)
3.在pom.xml文件中增加依赖项
<dependency> <groupId>axis</groupId> <artifactId>axis</artifactId> <version>1.4.17</version> </dependency>
<dependency> <groupId>axis</groupId> <artifactId>jaxrpc</artifactId> <version>1.4.17</version> </dependency>
第二种:修改pom.xml文件(正在用)
1、对于jar包
maven插件spring-boot-maven-plugin中添加配置<includeSystemScope>true</includeSystemScope>配置,如下:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
</plugins>
</build>
然后,添加依赖项:
打包后,在lib文件夹下,其中的一个jar
2、对于war包
war包打包后会生成一个WEB-INF/lib-provided的文件夹,访问时,会报错,因为tomcat是读取WEB-INF/lib里的jar包
需要添加maven-war-plugin插件,
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<directory>lib</directory>
<targetPath>WEB-INF/lib/</targetPath>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
打war包后,仍然会有lib-provided文件夹,而在lib下存在第三方jar包
参考如下:
https://www.cnblogs.com/xmqa/p/8862783.html https://blog.csdn.net/qq_34176290/article/details/115763520