posts - 106,  comments - 10,  views - 42万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

项目依赖的一个jar包是在开发环境的maven 私有仓库获取的,在部署的环境中没法获取到,所以采取了将jar包放在项目目录下,pom中添加本地依赖的方式

1 通过scope:system引入

  把jar包放在根目录下的lib包中,添加依赖  

1 <dependency>
2     <groupId>**</groupId>
3     <artifactId>x</artifactId>
4     <version>2.2-SNAPSHOT</version>
5     <scope>system</scope>
6     <systemPath>${project.basedir}/lib/**.x.2.2-SNAPSHOT.jar</systemPath>
7 </dependency>

 

使用这种方式不可行,因为 scope:system和scope:system的依赖范围作用相同,即对于编译和测试classpath有效,运行时无效

2 将jar包装载到本地仓库

  命令:

复制代码
 1 mvn install:install-file  
 2   -Dfile=<path-to-file>  
 3   -DgroupId=<group-id>  
 4   -DartifactId=<artifact-id>  
 5   -Dversion=<version>  
 6   -Dpackaging=<packaging>  
 7   -DgeneratePom=true  
 8   
 9 Where: <path-to-file>  the path to the file to load  
10        <group-id>      the group that the file should be registered under  
11        <artifact-id>   the artifact name for the file  
12        <version>       the version of the file  
13        <packaging>     the packaging of the file e.g. jar  
复制代码

pom依赖

<dependency>
    <groupId>**</groupId>
    <artifactId>x</artifactId>
    <version>2.2-SNAPSHOT</version>
</dependency>
 
 这样就可以在编译、测试、运行时都能被加载到
posted on   赵羴  阅读(3060)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示