zoukankan      html  css  js  c++  java
  • maven的中传递依赖,maven的依赖管理(转)

    在maven的pom文件中

    <dependencies>
           <dependency> 
             <groupId>junit</groupId> 
             <artifactId>junit</artifactId> 
             <version>3.8.1</version> 
             <scope>test</scope> 
           </dependency> 
         </dependencies> 

    那这个例子很简单,但是实际开发中我们会有复杂得多的依赖关系,因为被依赖的 jar 文件会有自己的依赖关系。那么我们是不是需要把那些间接依赖的 jar 文件也都定义在POM中呢?答案是不需要,因为 maven 提供了传递依赖的特性。

    所谓传递依赖是指 maven 会检查被依赖的 jar 文件,把它的依赖关系纳入最终解决的依赖关系链中。针对上面的 junit 依赖关系,如果你看一下 maven 的本地库(我们马上会解释 maven 库)~/.m2/repository/junit/junit/3.8.1/ ,

    part2-1

    你会发现 maven 不但下载了 junit-3.8.1.jar,还下载了它的 POM 文件。这样 maven 就能检查 junit 的依赖关系,把它所需要的依赖也包括进来。

    在 POM 的 dependencies 部分中,scope 决定了依赖关系的适用范围。我们的例子中 junit 的 scope 是 test,那么它只会在执行 compiler:testCompile and surefire:test 目标的时候才会被加到 classpath 中,在执行 compiler:compile 目标时是拿不到 junit 的。

    我们还可以指定 scope 为 provided,意思是 JDK 或者容器会提供所需的jar文件。比如说在做web应用开发的时候,我们在编译的时候需要 servlet API jar 文件,但是在打包的时候不需要把这个 jar 文件打在 WAR 中,因为servlet容器或者应用服务器会提供的。

    scope 的默认值是 compile,即任何时候都会被包含在 classpath 中,在打包的时候也会被包括进去。
     转自:http://www.oracle.com/technetwork/cn/community/java/apache-maven-getting-started-2-405568-zhs.html

  • 相关阅读:
    TC79
    SQL TUNNING
    Oracle PLSQL
    DB String Split sample
    dw websites
    Load xlsx in a folder to RDBMS table with Talend
    Reading WebSites
    SQOOP Load Data from Oracle to Hive Table
    dotnet use regex two samples
    Excel scientific notation issue
  • 原文地址:https://www.cnblogs.com/fatfatdachao/p/4353731.html
Copyright © 2011-2022 走看看