代码之家  ›  专栏  ›  技术社区  ›  Ishita Shah Y_Sh

Maven测试不使用外部JAR运行

  •  1
  • Ishita Shah Y_Sh  · 技术社区  · 6 年前

    maven项目,其中一个外部jar已导入,

    项目(mvn test)按照为@test类定义的方式成功运行,如果没有外部jar,请参考项目。

    但如果项目中有可用的外部JAR,它就不能运行(MVN测试)。

    是否有任何插件或引用可以通过引用调用MVN测试来使用外部JAR?

    但如果项目中有可用的外部JAR,它就不能运行(MVN测试)。

    enter image description here

    是否有任何插件或引用可以通过引用调用MVN测试来使用外部JAR?

    1 回复  |  直到 6 年前
        1
  •  2
  •   RamanaMuttana    6 年前
    mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
        -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
    

    https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

    首先,在命令提示中按照上面的代码将外部jar添加到.m2存储库中。

    第二种方法:

    直接将外部JAR信息添加到pom.xml文件中,如下所示,

    <dependency>
        <groupId>your external jar groupid</groupId>
        <artifactId>your jar artifactid</artifactId>
        <version>version of your external jar</version>
        <scope>system</scope>//this should be system only 
        <systemPath>C:/Users/Desktop/external.jar</systemPath>// path of the external jar.
    </dependency>
    

    因此,您可以将外部JAR添加到系统中的Maven存储库中。当Maven尝试加载依赖项时,它将从Maven中央存储库的本地inspite将外部JAR加载到您的项目中。