maven引用本地jar包

一、maven打包本地jar包到本地仓库

使用场景

  1. maven依赖需要对本地自己写的jar包进行引用;
  2. 远程仓库不存在某jar包,手工加载后,打入仓库

 

执行指令

在控制台执行:

mvn install:install-file -Dfile=jar包的位置  -DgroupId=groupId  -DartifactId=artifactId  -Dversion=version  -Dpackaging=jar

其中,groupId,artifactId,version三个字段值可以自定义赋值。但要保证跟pom.xml中对应。

打包命令执行成功后,maven执行reimport,检查pom.xml是否还有报错。

 

示例:

mvn install:install-file -Dfile=D:\setup\fastdfs-client-java-1.27-RELEASE.jar -DgroupId=org.csource -DartifactId=fastdfs-client-java -Dversion=1.27-SNAPSHOT -Dpackaging=jar

 

错误

Q:报错:[ERROR] The goal you specified requires a project to execute but there is no POM in this directory

A:

解决方案一:将相关参数加上引号

mvn install:install-file "-Dfile=D:\setup\fastdfs-client-java-1.27-RELEASE.jar" "-DgroupId=org.csource" "-DartifactId=fastdfs-client-java" "-Dversion=1.27-SNAPSHOT" "-Dpackaging=jar"

大神指出该问题主要是使用PowerShell执行install命令时的错误,且可能跟maven版本有关。

详见:

https://stackoverflow.com/questions/16348459/error-the-goal-you-specified-requires-a-project-to-execute-but-there-is-no-pom

解决方案二:检查一下install命令是否全是英文字符

 

章节一参考:

https://www.cnblogs.com/panchanggui/p/10696458.html

 

二、pom.xml指定本地路径

<dependency>
      <groupId>your.organization</groupId>
      <artifactId>your-sdk-util</artifactId>
      <version>1.1.1.0</version>
      <scope>system</scope>
      <systemPath>${pom.basedir}/lib/your-sdk-ver.jar</systemPath>
</dependency>

其中,${pom.basedir}表示项目根路径。groupId,artifactId,version自定义设置,但是scope必须设置成system。

 

注意

这样设置后pom.xml不会报错,但是如果需要使用maven进行打包时,scope为system的依赖包不会被maven打包进项目。

需要为pom.xml的打包插件配置includeSystemScope属性。

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <includeSystemScope>true</includeSystemScope>
                <fork>true</fork>
            </configuration>
        </plugin>
    </plugins>
</build>

(未实际验证,参考:https://blog.csdn.net/beeworkshop/article/details/104727363

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值