maven添加本地包依赖

 1、通过 <scope>system</scope> 的依赖方式引入

    2、通过mvn install 命令将依赖包添加到本地maven仓库

1、<scope>system</scope> 的依赖方式引入
比如项目目录下有lib/errorWordsCore-1.0.jar
需求:maven项目需要引入本地一个jar包。并且打包后需要把该文件引入依赖。

比如项目目录下有lib/errorWordsCore-1.0.jar
将jar包引入pom.xml

        <dependency>
           <groupId>com.hugedata.core</groupId>
            <artifactId>errorword</artifactId>
            <version>1.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/errorWordsCore-1.0.jar</systemPath>
        </dependency>
scope 为system。此时必须提供systemPath即本地依赖路径。表示maven不会去中央仓库查找依赖。要注意的是这个范围是不推荐使用的。

	<build>
	    <finalName>${project.artifactId}</finalName>
	    <plugins>
	        <plugin>
	            <groupId>org.springframework.boot</groupId>
	            <artifactId>spring-boot-maven-plugin</artifactId>
	            <configuration>
	                <fork>true</fork> <!-- 如果没有该配置,devtools不会生效 -->
                    <includeSystemScope>true</includeSystemScope>
	            </configuration>
	        </plugin>
	    </plugins>
	</build>

将jar包加入classpth,同样在pom.xml。 打包时把errorWordsCore-1.0.jar一并打包到lib。在assembly的xml文件中,表示把pom范围是system的依赖也打包到lib目录

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.albert.Application</mainClass>
                        <classpathPrefix>lib/</classpathPrefix>
                        <addClasspath>true</addClasspath>
                    </manifest>
                    <manifestEntries>
                        <!-- 在Class-Path下添加配置文件的路径 -->
                        <Class-Path>lib/my-dep-1.0.jar</Class-Path>         
                        <!--这里表示jar路径加入到MANIFEST.MF-->              
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>
注意:有时打出来的包里面没有本地包,不知道什么原因,打包后最后打开查看一下

2、mvn install 命令将依赖包添加到本地maven仓库
(1)添加到本地maven仓库
mvn install:install-file -DgroupId=com.fnii.core -DartifactId=errorWordsCore -Dversion=1.0 -Dpackaging=jar -Dfile=errorWordsCore-1.0.jar
 

DgroupId:组名,就是自己的包名

DartifactId

Dversion:版本

Dfile:指定文件,这里是指定当前目录下

(2)maven的pom文件中正常添加依赖


发现在pom.xml文件里面可以完美的依赖了
————————————————
版权声明:本文为CSDN博主「mengao1234」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/mengo1234/article/details/109576609

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值