Maven2的对象模型POM

pom作为项目对象模型,通过xml表示maven项目,使用pom.xml文件来实现。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
< project  xmlns = "http://maven.apache.org/POM/4.0.0"
          xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
             http://maven.apache.org/xsd/maven-4.0.0.xsd">
     < modelVersion >4.0.0</ modelVersion >
     <!-- 基本设置 -->
     < groupId >...</ groupId <!-- 项目或者组织的唯一标志,并且配置时生成的路径也是由此生成,如org.codehaus.mojo生成的相对路径为/org/codehaus/mojo -->
     < artifactId >...</ artifactId >   <!--项目的通用名称-->
     < version >...</ version >   <!--项目的版本-->
     < packaging >...</ packaging >   <!--打包的机制-->
     < dependencies >...</ dependencies >
     < parent >...</ parent >
     < dependencyManagement >...</ dependencyManagement >
     < modules >...</ modules >
     < properties >...</ properties >
     <!-- 构建过程的设置 -->
     < build >...</ build >
     < reporting >...</ reporting >
     <!-- 项目信息设置 -->
     < name >...</ name >
     < description >...</ description >
     < url >...</ url >
     < inceptionYear >...</ inceptionYear >
     < licenses >...</ licenses >
     < organization >...</ organization >
     < developers >...</ developers >
     < contributors >...</ contributors >
     <!-- 环境设置 -->
     < issueManagement >...</ issueManagement >
     < ciManagement >...</ ciManagement >
     < mailingLists >...</ mailingLists >
     < scm >...</ scm >
     < prerequisites >...</ prerequisites >
     < repositories >...</ repositories >
     < pluginRepositories >...</ pluginRepositories >
     < distributionManagement >...</ distributionManagement >
     < profiles >...</ profiles >
</ project >

pom定义了最小的maven2元素,允许groupId,artifactId,version的所有需要的元素。

pom关系:依赖,集成,合成

依赖关系:

1
2
3
4
5
6
7
8
9
10
11
< dependencies
     < dependency
         < groupId >junit</ groupId
         < artifactId >junit</ artifactId
         < version >4.0</ version
         < type >jar</ type
         < scope >test</ scope
         < optional >true</ optional
     </ dependency
     ... 
</ dependencies >

继承关系

1
2
3
4
5
6
7
< project >
     < modelVersion >4.0.0</ modelVersion >
     < groupId >org.codehaus.mojo</ groupId >
     < artifactId >my-parent</ artifactId >
     < version >2.0</ version >
     < packaging >pom</ packaging >
</ project >

合成(或者多个模块)

一个项目有多个模块,也叫做多重模块,或者合成项目。

1
2
3
4
5
6
7
8
9
10
< project >
     < modelVersion >4.0.0</ modelVersion >
     < groupId >org.codehaus.mojo</ groupId >
     < artifactId >my-parent</ artifactId >
     < version >2.0</ version >
     < modules >
         < module >my-project1< module >
         < module >my-project2< module >
     </ modules >
</ project >

插件

在build时,执行的插件,比较有用的部分,如使用jdk6.0编译等等

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
< project >
     < build >
     ...
     < plugins >
         < plugin >
             < groupId >org.apache.maven.plugins</ groupId >
             < artifactId >maven-jar-plugin</ artifactId >
             < version >2.0</ version >
             <!-- true或false,是否加载插件扩展,默认false-->
             < extensions >false</ extensions >
             <!-- true或false,是否此插件配置会应用与pom-->
             < inherited >true</ inherited >
             <!-- 指定插件配置-->
             < configuration >
                 < classifier >test</ classifier >
             </ configuration >
             <!-- 插件需要依赖的包-->
             < dependencies >...</ dependencies >
             <!-- 用于配置execution目标,一个插件可以有多个目标-->
             < executions >...</ executions >
         </ plugin >
     </ plugins >
     </ build >
</ project >










本文转自 LinkedKeeper 51CTO博客,原文链接:http://blog.51cto.com/sauron/1268834,如需转载请自行联系原作者
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值