项目依赖的一个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 2022-07-20 15:02  赵羴  阅读(3048)  评论(0编辑  收藏  举报