mave的pom文件

1) pom.xml构成

modelVersion 指定当前pom的版本

groupId  反写的工程网址+项目名

artifactId  项目名+模块名

version :版本 (三部分:

第一部分为大版本号,

第二个表示分支版本号

第三个为小版本号

0.0.1

snapshot 快照

alpha 内部测试

beta 公测

Release 稳定

GA 正式发布

)

packaging 默认为jar [war zip pom]

name:项目描述名

url:项目地址

description 项目描述

。。。

重要的依赖标签:

    <dependencies>

<dependency>

    <groupId>junit</groupId>

     <artifactId>junit</artifactId>

     <version>3.8.1</version>

     <!-- 依赖范围-->

     <scope>test</scope>

    <!--设置依赖是否可选 -->

     <optional></optional>

     <!-- 排除依赖传递列表 -->

     <exclusions>

<exclusion></exclusion>

     </exclusions>

 </dependency>

     </dependencies>

  

   <!-- 依赖管理 -->

  <dependencyManagement>

  <dependencies>

  <dependency></dependency>

  </dependencies>

  </dependencyManagement>

  

  <build>

  <!-- 插件列表 -->

  <plugins>

  <plugin>

  </plugin>

  </plugins>

  </build>

  

  <parent></parent>

  <!-- 多个模块的编译 -->

  <modules></modules>

  2) maven依赖范围

     scope标签定义

     参数可选值:6个 

     compile 默认的范围,编译测试运行都有效

     provided 在编译和测试时有效

     runtime  在测试和运行时有效

     test 只会在测试范围有效

     system 与本机系统相关联,可移植性差

     import 导入的范围,它只使用在dependencyManagement中,表示从其他的pom中导入dependecy的配置

 3) maven依赖

    依赖之前的工程必须先打包,再运行才不会报错。

    

    依赖冲突:

     a) 短路优先

        eg:A->B->C-X(jar)  与A->D->X(jar)

则会选择后边的路径;

     

     b)路径相同,选择配置文件在前边的依赖。

4) 聚合和继承

   聚合:将多个模块在一起执行

    eg:

    <modules>

<module>[模块工程的路径以及名字../project-name]</module>

...

    </modules>

    继承:

**可以写el表达式  eg: ${junit.version}

5) 构建web项目

  需要手动导入servlet依赖

猜你喜欢

转载自luckylearn.iteye.com/blog/2382542