Anti

Anti's BlogJava

POM.XML的例子

<?xml version="1.0" encoding="UTF-8"?>
<project
    
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns
="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    ...
</project>
1 表框架 

<!-- The Basics -->
  <groupId></groupId>
  <artifactId></artifactId>
  <version></version>
  <packaging></packaging>
  <dependencies></dependencies>
  <parent></parent>
  <dependencyManagement></dependencyManagement>
  <modules></modules>
  <properties></properties>
2 基本内容: POM包含了所有项目信息。
  groupId: 项目或组织的唯一标示,路径由此生成。
  artifactId: 项目通用名称
  version: 项目版本
  packaging: 打包机制,pom, jar, maven-plugin, ejb, war, ear, rar, par 
  classifier: 分类

3 POM关系:依赖,继承,合成
-3.1 依赖关系:
<dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.0</version>
      <type>jar</type>
      <scope>test</scope>
      <optional>true</optional>
    </dependency>
    
  </dependencies>
  groupId, artifactId, version: 依赖的唯一标示
  type: 相应的依赖产品的形式,如jar, war
  scope: 限制依赖范围,包括
     compile: 默认,用于编译
      provided: 类似于编译,但支持你期待的jdk或容器提供,类似classpath
      runtime: 在执行时需要使用
      test: 用于test任务时使用
      system: 需要外在提供相应元素,通过systemPath获取
  systemPath: 标注<scope>system</scope>的路径
  optional: 标注可选,当项目自身也是依赖时,用于连续依赖时使用

-3.2 独占性
<dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-hibernate3</artifactId>
            <version>2.0.8</version>
            <exclusions>
                <exclusion>
                    <artifactId>jta</artifactId>
                    <groupId>javax.transaction</groupId>
                </exclusion>
            </exclusions>
        </dependency>
告诉maven只包括指定项目,不包括相关依赖。主要用于解决版本冲突。
eg中表示项目spring-hibernate3需要项目jta,但是我们不想引用jta。

-3.3继承关系
  父项目
<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>my-parent</artifactId>
  <version>2.0</version>
  <packaging>pom</packaging>
</project>
  子项目
<project>
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>my-parent</artifactId>
    <version>2.0</version>
    <relativePath>../my-parent</relativePath>
  </parent>
  <artifactId>my-project</artifactId>
</project>
relativePath可以不需要,但是用于指明parent的目录,用于快速查找。

4 合成(多模块)
<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>

5 for more information, get this.
http://www.blogjava.net/zyl/archive/2006/12/30/91055.html

posted on 2012-02-02 14:22 Anti 阅读(712) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: