博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
maven引用本地jar
阅读量:7096 次
发布时间:2019-06-28

本文共 3344 字,大约阅读时间需要 11 分钟。

hot3.png

    在使用maven进行jar包管理时,通过我们都是通过maven去下载一些jar包,但有些jar在maven上没有,所以就就可能在本地直接手动加入一些需要用到的外部jar包。但如果我们用maven package打包就会发现,本地的那些jar是不能被maven识别的,所以就需要解决Maven关于本地jar包的打包处理的问题。

1. 使用system scope

org.sky
my-jar
1.0
system
   
e:\my-jar.jar

编译后出现一个警告:

[WARNING] 'dependencies.dependency.systemPath' for org.sky:my-jar:jar should use a variable instead of a hard-coded path e:\my-jar.jar @ line 35, column 16

[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.

 

原来是 maven 苦口婆心地告诉我们不要使用诸如 C:\Windows 这样的绝对路径,而应使用 ${java.home} 这样的相对路径(变量),否则降低了编译可重现性,并威胁我们以后可能不再支持这种方式。

后来改成<systemPath>${project.basedir}/lib/my-jar.jar</systemPath>, 结果说找不到z这个jar,无解了。

system scope引入的包,在使用jar-with-dependencies打包时将不会被包含,可以使用resources将本地包打进jar-with-dependencies

org.apache.maven.plugins
maven-shade-plugin
make-assembly
package
shade
jar-with-dependencies
xxx-jar-with-dependencies
lib/
lib/
**/my-jar.jar

生成的xxx-jar-with-dependencies.jar中,将会包含lib目录以及my-jar.jar,并且能够被在执行的时候被找到。我反正没试过。还有看到网上说添加下面一段。

maven-compiler-plugin
2.3.2
1.7
1.7
UTF-8
project-demo\lib
    

2.使用指令 mvn install:install-file 将jar文件安装到本地仓库

语法规范:

mvn install:install-file  -Dfile=
-DgroupId=
-DartifactId=
-Dversion=
-Dpackaging=
-DgeneratePom=true Where:
the path to the file to load
the group that the file should be registered under
the artifact name for the file
the version of the file
the packaging of the file e.g. jar

mvn install:install-file -Dfile=e:\ojdbc6.jar -DgroupId=ojdbc -DartifactId=ojdbc -Dversion=6 -Dpackaging=jar -DgeneratePom=true

 

3. 添加 in project repository,在新机器上执行时就不用运行mvn install:install-file命令了

in-project
In Project Repo
file://${project.basedir}/lib
org.richard
my-jar
1.0

你的jar包及路径必须严格遵循格式:

/groupId/artifactId/version/artifactId-verion.jar

本例中: lib/org/richard/my-jar/1.0/my-jar-1.0.jar

 

参考地址:http://stackoverflow.com/questions/3642023/having-a-3rd-party-jar-included-in-maven-shaded-jar-without-adding-it-to-local-r

转载于:https://my.oschina.net/u/1432675/blog/746172

你可能感兴趣的文章
思科SG300,SG500,SF300,SF500系统默认VLAN解析
查看>>
vi速查
查看>>
挨踢项目求生法则——测试篇
查看>>
mysql找回管理员密码
查看>>
secure_file_priv参数说明
查看>>
python 500 lines or less 参考地址
查看>>
IT必备技术
查看>>
Ruby编程规约
查看>>
LCS算法取两个字符串最大子串
查看>>
Go语言中的string知识点
查看>>
2013-10-6 datagridview实现换行并自动设置行高
查看>>
修正zen cart商品评论显示太短的问题
查看>>
linux-awk
查看>>
SpringMVC框架的多表查询和增删查改
查看>>
记一次TFS 的 垃圾提示(无法下载 未获取项目 的 代码)
查看>>
NGINX基本配置与参数说明
查看>>
关于TP出现_STORAGE_WRITE_ERROR_的解决方案
查看>>
1833. [ZJOI2010]数字计数【数位DP】
查看>>
leaflet入门(四)API翻译(上)
查看>>
B.小A与任务
查看>>