zoukankan      html  css  js  c++  java
  • Maven介绍

    1.Maven约定优于配置---它提出这一概念,为项目提供合理的默认行为,无需不必要的配置。提供了默认的目录

      src                   ——>         源代码和测试代码的根目录

        main                            应用代码的源目录

          java                     源代码

          resources           项目的资源文件

        test                               测试代码的源目录

          java                      测试代码

          resources            测试的资源文件

      target                                   编译后的类文件、jar文件等

    2.Dependencies & DependencyManagement 区别

      a.DependencyManagement 主要应用场景:项目模块很多的时候,需要抽象出一个父工程(parent)进行管理项目子模块及Jar包,

        在项目顶层的POM文件中,我们会看到dependencyManagement元素,通过它元素来管理jar包的版本,让子项目中引用一个依赖而不用显示的列出版本号,若列出版本号,则子模块的版本将覆盖父项目中指定的版本

        Maven会沿着父子层次向上走,直到找到一个拥有dependencyManagement元素的项目,然后它就会使用在这个dependencyManagement元素中指定的版本号。

    Ps:DependencyManagement 中的管理的Jar,在子模块中必须显示引用Dependencies即使在子项目中不写该依赖项,那么子项目仍然会从父项目中继承该依赖项(全部继承).

    <!--父项目 POM配置文件-->
    <properties><!--统一定义版本号-->
        <servlet-version>2.5</servlet-version>
        <junit-version>4.12</junit-version>
        <junit-scope>test</junit-scope>
    </properties>
    
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>${junit-version}</version>
                <scope>${junit-scope}</scope>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
                <version>${servlet-version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
    
    
    <!--子项目 POM配置文件-->
    <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <!--子项目模块中,需要显示进行引用;同时可以不用列出版本号(继承父类的version、scope);若列出了版本,则覆盖父类的版本--> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> </dependency> </dependencies>

      2.1 解决兄弟子项目之间的依赖问题:

      场景:在两个平级的子项目模块之间互相依赖,以下存在groupId、version重复的问题

    <dependencies>
         <dependency>
              <groupId>com.lance</groupId>  <!-- <groupId>${parent.groupId}</groupId> -->
              <artifactId>A</artifactId>
              <version>1.0-SNAPSHOT</version>   <!--  <version>${parent.version}</version> -->
         </dependency>
         <dependency>
              <groupId>com.lance</groupId>  
              <artifactId>B</artifactId>
              <version>1.0-SNAPSHOT</version>
          </dependency>
    </dependencies> 

    解决方法:

    <groupId>${parent.groupId}</groupId>   <version>${parent.version}</version>
    当然,也可以使用property进行定义
     
     
  • 相关阅读:
    LR--用栈实现移进--归约分析(demo)
    阿里云ECS服务器socket无法连接的问题
    select客户端模型封装——回调方式快速建立客户端
    select服务器端模型封装——回调方式快速建立服务端
    python实现的ocr接口
    汉字字典树
    linux下简易端口扫描器
    Linux下cs简单通讯(socket)
    POj 1321 棋盘问题 DFS 回溯
    HDU 1097 快速幂
  • 原文地址:https://www.cnblogs.com/swugogo/p/7694280.html
Copyright © 2011-2022 走看看