Maven学习小结

    Maven做为一个项目管理工具,通常用来构建项目,和管理项目中lib之间的依赖关系。

 
   1. 约定先于配置(Maven有一组默认约定可用,基本不需要再配置,与Ant相比,这是比较人性化的一个特点)如:Maven项目标准目录布局
src/main/javaApplication/Library sources
src/main/resourcesApplication/Library resources
src/main/filtersResource filter files
src/main/assemblyAssembly descriptors
src/main/configConfiguration files
src/main/scriptsApplication/Library scripts
src/main/webappWeb application sources
src/test/javaTest sources
src/test/resourcesTest resources
src/test/filtersTest resource filter files
src/siteSite
LICENSE.txtProject's license
NOTICE.txtNotices and attributions required by libraries that the project depends on
README.txtProject's readme
 
    2.Maven核心概念
        1)插件和目标(Plugins & goals)
        Maven是基本插件的,基本全部功能全是靠插件目标完成的,如 $mvn complier:compile是调用了complier插件的compile目标。
        一个插件是一个或多个目标的集合。
 

    2)构建生命周期(buil lifecycle)
        Maven有3个内置的构建生命周期:default, clean, site。每个生命周期都有好几个默认的阶段(phase)。 每个阶段定义了到这一步要完成的任务,当执行这一阶段时,之前的阶段会先依次执行再执行当前阶段。各个阶段上绑定了零个或多个插件目标,执行阶段,其实就是依次执行其上绑定的插件目标。 

    3)Maven坐标(Coordinates)Maven定义了一组标识,来唯一标识一个项目、一个依赖或者一个插件。通过groupId, artifactId,version,packaging四元组来标识一个项目的坐标。Maven仓库(Repository)通过坐标来定位相应的构件。

    4)Maven仓库(Repository)Maven仓库中存放着一些构件,根据坐标可查找到相应的构件。只有2种类型的仓库local和remote。当项目需要使用构件时,先查找local仓库,如果没有会从remote仓库上下载到local仓库。

    5)依赖管理(Dependencies Management)Dependency management is one of the features of Maven that is best known to users and is one of the areas where Maven excels(擅长)。传递依赖(Transitive Dependencies)allows you to avoid needing to discover and specify the libraries that your own dependencies require, and including them automatically。

    3.Maven Archetype 插件

     In short, Archetype is a Maven project templating toolkit. An archetype is defined as an original pattern or model from which all other things of the same kind are made。 Archetype插件共有4个目标:generate, create-from-project, crawl, create(@deprecated)。

 mvn archetype:generate是根据一个原始模型,生成一个项目。

    

    4.POM     

    A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project. It contains default values for most projects.在POM里可以指定项目的依赖,执行的插件和目标,以及项目的版本、描述、开发者、邮件列表等等。

 

    1)Super POM

    所有的Maven项目的POM都扩展自Super POM,Super POM定义了一组被所有项目共享的默认设置。Maven 3.x的Super POM在${M2_HOME}/lib/maven-model-builder-3.0.4.jar/org.apache.maven.model/pom-4.0.0.xml.部分代码

 

<build>

    <directory>${project.basedir}/target</directory>

    <outputDirectory>${project.build.directory}/classes</outputDirectory>

    <finalName>${project.artifactId}-${project.version}</finalName>

    <testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>

    <sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>

    <scriptSourceDirectory>src/main/scripts</scriptSourceDirectory>

    <testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>

    <resources>

      <resource>

        <directory>${project.basedir}/src/main/resources</directory>

      </resource>

    </resources>

    <testResources>

      <testResource>

        <directory>${project.basedir}/src/test/resources</directory>

      </testResource>

    </testResources>

    <pluginManagement>

      <!-- NOTE: These plugins will be removed from future versions of the super POM -->

      <!-- They are kept for the moment as they are very unlikely to conflict with lifecycle mappings (MNG-4453) -->

      <plugins>

        <plugin>

          <artifactId>maven-antrun-plugin</artifactId>

          <version>1.3</version>

        </plugin>

        <plugin>

          <artifactId>maven-assembly-plugin</artifactId>

          <version>2.2-beta-5</version>

        </plugin>

        <plugin>

          <artifactId>maven-dependency-plugin</artifactId>

          <version>2.1</version>

        </plugin>

        <plugin>

          <artifactId>maven-release-plugin</artifactId>

          <version>2.0</version>

        </plugin>

      </plugins>

    </pluginManagement>

  </build>

 

    

转载于:https://www.cnblogs.com/cuillgln/archive/2012/05/03/2481473.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值