Maven pom.xml 添加本地jar包依赖以及打包方法
Maven项目打包时,如果遇到需要添加本地jar包依赖的时候,可以选择两种方法:
1.安装到本地仓库
第一种方法比较常规,适用于需要添加的jar包也是由maven项目导出,含有pom文件的时候。只需要将jar包安装到本地maven仓库下,然后添加依赖即可。
(1)安装到本地仓库,执行以下命令(其中的-Dfile/-DgroupId/-DartifactId/-Dversion项根据pom文件内容填写):
mvninstall:install-file-Dfile=xxxxx.jar-DgroupId=xxx.xxx.xxx-DartifactId=xxxxx-Dversion=1.0.0-Dpackaging=jar
(2)安装之后可以在本地仓库中找到对应的jar包。然后将对应的依赖信息插入到工程的pom文件即可:
xxx.xxx.xxx xxxxx 1.0.0
2.dependency中指定scope="system"和本地jar包路径
这种方法适用于其他方式导出的jar包,jar包中不含有pom信息,从而无法安装进本地仓库的情况。做法是:先配置本地jar包依赖,然后在build时将设置将jar包导出,同时配置manifest。
(1)配置本地jar包依赖(systemPath指向本地jar包路径):
com.amazonaws aws-java-sdk-s3 1.11.0 system ${project.basedir}/lib/xxx.jar
(2)在
org.springframework.boot spring-boot-maven-plugin true
(3)如果项目使用maven-jar-plugin插件打包的话,还需要在manifectEntries中添加对应的jar包信息;否则虽然jar包导出了,但是项目生成的MANIFEST.MF文件中没有对应的依赖信息,也会导致运行时找不到对应的class。
org.apache.maven.plugins maven-jar-plugin true lib/ XXXX ./lib/xxxxx.jar ${project.build.directory}/XXXXX
(4)最后附上一个项目完整的
XXXXX src/main/java src/main/resources ${project.build.directory}/XXXXX **/*.java src/test/java src/test/resources true **/*.java org.springframework.boot spring-boot-maven-plugin true org.apache.maven.plugins maven-surefire-plugin true org.apache.maven.plugins maven-dependency-plugin copy-dependencies package copy-dependencies ${project.build.directory}XXXXX/lib org.apache.maven.plugins maven-jar-plugin true lib/ xxx.xxx.XXXXX ./lib/xxxxx.jar ${project.build.directory}/XXXXX
到此这篇关于Mavenpom.xml添加本地jar包依赖以及打包方法的文章就介绍到这了,更多相关Mavenpom.xmljar包内容请搜索毛票票以前的文章或继续浏览下面的相关文章希望大家以后多多支持毛票票!
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。