Maven学习二: Maven POM

来源:互联网 发布:淘宝怎样退出虚拟类目 编辑:程序博客网 时间:2024/05/11 15:22
      本是打算通过学用Maven来把Rest Demo的Jersey框架相关jar包管理并使用起来,结果发现Maven这个工具我并不熟悉的,于是算作一个小插曲,先把略微系统性的学习一下Maven的配置以及使用等等。

     前两篇文章,把Maven的环境配置说了一下,这并不是Maven的入门,而是刚刚具备了入门的基础。

     Maven POM,就是Maven 管理下的Project Object Model,代表项目对象模型。它是工作在Maven的基本单位。这是一个XML文件。它包含的项目使用Maven来构建该项目和各种配置的详细信息。

     POM也包含了目标和插件。在执行任务或目标时,Maven会找到在当前目录中的POM文件并进行读取,得到所需要的配置信息,然后执行的目标。部分的配置,可以在POM如下:

  • project dependencies

  • plugins

  • goals

  • build profiles

  • project version

  • developers

  • mailing list

    创建一个POM之前,我们应该先决定项目组(groupId),它的名字(artifactId)和它的版本,因为这些属性是用来作唯一标示的。

    例子POM

<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>com.companyname.project-group</groupId> <artifactId>project</artifactId> <version>1.0</version> </project>
应当指出,应该有一个单一的POM文件为每个项目。

  • 所有的POM文件要求的项目元素和三个必填字段: groupId,artifactId版本。

  • 在库中的项目符号是:groupId:artifactId:version.

  • 根元素的pom.xml是项目,它有三个主要的子节点:

NodeDescriptiongroupIdThis is an Id of project's group. This is generally unique amongst an organization or a project. For example, a banking group com.company.bank has all bank related projects.artifactIdThis is an Id of the project.This is generally name of the project. For example, consumer-banking. Along with the groupId, the artifactId defines the artifact's location within the repository.versionThis is the version of the project.Along with the groupId, It is used within an artifact's repository to separate versions from each other. For example: 

com.company.bank:consumer-banking:1.0

com.company.bank:consumer-banking:1.1.



原创粉丝点击