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进行定义
     
     
  • 相关阅读:
    这个帖子主要总结数据库备份方面的问题
    Visual C#.Net 网络程序开发Socket篇
    数据库设计说明书参考模板
    用Visual C#开发WinForm的应用程序
    在ASP.NET页中读取文本文件
    如何通过 SQL Server 链接服务器和分布式查询使用 Excel
    ER概念模型
    SQL Server 存储过程的分页方案比拼
    读出某一个目录的文件和文件夹
    Linux中的定时任务简单操作实例
  • 原文地址:https://www.cnblogs.com/swugogo/p/7694280.html
Copyright © 2011-2022 走看看