美文网首页
Maven中使用本地第三方jar包引用

Maven中使用本地第三方jar包引用

作者: 双流小二郎 | 来源:发表于2018-09-26 15:51 被阅读0次

    Maven使用起来非常方便,大多常用的包都可以在远程仓库Maven Repository中找到,只需要在pom.xml中添加依赖即可引用。但是我们日常开发中会用到一些本地第三方jar包,介绍两种方法使用。

    1. 将jar包添加到本地仓库中

    参考Guide to installing 3rd party JARs
    我在程序根目录新建了lib文件夹用于存储第三方jar包,内有suitetalk-client-common-1.0.0.jar

    // cmd进入应用根目录,运行命令
    mvn install:install-file -Dfile=./lib/suitetalk-client-common-1.0.0.jar 
    -DgroupId=com.netsuite.ccsc 
    -DartifactId=suitetalk-client-common 
    -Dversion=2017.2
    -Dpackaging=jar
    

    pom.xml中这样引用

    <dependency>
      <groupId>com.netsuite.ccsc</groupId>
       <artifactId>suitetalk-client-common</artifactId>
       <version>2017.2</version>
    </dependency>
    

    需注意groupIdartifactIdversion参数需要一一对应。

    2.使用 System Dependency Scope

    参考Maven System Dependencies

    system
    This scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository.

    就是说System Scope的引用不会在仓库中查找,需要显示的提供jar包具体路径。在pom.xml中添加依赖如下

    <dependency>
        <groupId>com.ns.test</groupId>
        <artifactId>suitetalk-client-common</artifactId>
        <scope>system</scope>
        <systemPath>${project.basedir}/lib/suitetalk-client-common-1.0.0.jar</systemPath>
    </dependency>
    

    其中${project.basedir}指定为应用根目录,其中groupIdartifactIdversion参数随便填写不影响使用。

    结语

    推荐使用第一种方案,第二种我在打包时遇到了一些问题。

    相关文章

      网友评论

          本文标题:Maven中使用本地第三方jar包引用

          本文链接:https://www.haomeiwen.com/subject/jxtjoftx.html