zoukankan      html  css  js  c++  java
  • maven指定本地jar包

    来自 https://blog.csdn.net/zhengxiangwen/article/details/50734565

    一、怎么添加jar到本地仓库呢?
    步骤:
    1.cmd命令进入该jar包所在路径
    2.执行命令:
    mvn install:install-file -Dfile=lucene-queryparser-4.6.1.jar -DgroupId=org.apache.lucene -DartifactId=lucene-queryparser -Dversion=4.6.1 -Dpackaging=jar
    其中:-DgroupId和-DartifactId的作用是指定了这个jar包在repository的安装路径,只是用来告诉项目去这个路径下寻找这个名称的jar包。
    比如:
    mvn install:install-file -Dfile=hadoop-hdfs-2.2.0.jar -DgroupId=org.apache.hadoop -DartifactId=hadoop-hdfs -Dversion=2.2.0 -Dpackaging=jar
    就是指把hadoop-hdfs-2.2.0.jar安装到repositoryorg.apache.hadoophadoop-hdfs2.2.0目录下,执行完命令后,如果需要在项目中使用这个jar,则在pom.xml中添加如下配置即可:
    <dependency>
    <groupId>org.apache.hadoop</groupId>
    <artifactId>hadoop-hdfs</artifactId>
    <version>2.2.0</version>
    </dependency>

    注意在每个参数前有个-D

    二、怎么在pom.xml中添加项目中libs下的jar呢,而不是从本地仓库中添加?

    1、首先将要添加的jar包复制到项目中的libs文件夹下

    2、然后在pom.xml中添加如下代码:

    <dependency>
    <groupId>htmlunit</groupId>
    <artifactId>htmlunit</artifactId>
    <version>2.21-OSGi</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/libs/htmlunit-2.21-OSGi.jar</systemPath>
    </dependency>

    注意scope元素和systemPath元素,其中systemPath元素指定的就是jar包在项目中的路径。

    注意libs文件夹下的这个jar包不需要Add to Build Path
    下面是maven中央仓库的地址:http://mvnrepository.com/artifact/net.sourceforge.htmlunit/htmlunit/2.21

    可以在这里搜索想要的jar包,然后复制对应的依赖代码到你项目中的pom.xml中,则对应的jar包将下载到你本地的maven仓库中,以提供给你使用。

  • 相关阅读:
    sql内联、左联、右联
    如何在刷新页面时不提示 "重试或取消”对话框
    js判断一个元素是否存在的方法
    springboot--email
    AdvancedInstaller
    WebService
    WCF
    WebAPI
    关于Html class id 命名规范
    Jquery Ajax 复杂json对象提交到WebService
  • 原文地址:https://www.cnblogs.com/liuxm2017/p/10516076.html
Copyright © 2011-2022 走看看