如何使用maven的pom.xml来引用本地jar包

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

坐标可以任意给。${basedir}表示项目根目录。但打包时会出如下告警:

[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.wo:AlarmReport:jar:0.0.1-SNAPSHOT
[WARNING] 'dependencies.dependency.systemPath' for com.wo:taobao-sdk-java-auto:jar should not point at files within the project directory, ${basedir}/lib/taobao-sdk-java-auto.jar will be unresolvable by dependent projects @ line 61, 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.
[WARNING] 

所以需要把${basedir}改为${pom.basedir}

<systemPath>${pom.basedir}/lib/your-sdk-ver.jar</systemPath>

这样来抑制上述告警。

pom.xml文件的打包插件要配置includeSystemScope属性,否则scope为system的依赖包不会被maven打包进项目,导致打包后的项目无法引用本地的第三方jar包。

<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>
也可以把jar包通过maven安装到本地(仓库)再引用

操作步骤如下:

  1. cmd命令进入该jar包所在路径。

  2. 执行如下语句:

mvn install:install-file -Dfile=bdl-service-1.0-SNAPSHOT.jar -DgroupId=com.baidu -DartifactId=bdl-service -Dversion=1.0-SNAPSHOT -Dpackaging=jar

语句说明:把bdl-service-1.0-SNAPSHOT.jar安装到repository\com\baidu\bdl-service\1.0-SNAPSHOT\目录下。

-Dfile :本地jar包名称。

-DgroupId :安装到repository的中路径

-DartifactId :安装到repository的中路径

-Dversion :用来指定包的版本号

-Dpackaging :打包形式

  1. pom.xml中引用坐标:
<dependency>
  <groupId>com.baidu</groupId>
  <artifactId>bdl-service</artifactId>
  <version>1.0-SNAPSHOT</version>
</dependency>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值