Maven POM文件

简介

POM 代表项目对象模型。它是工作在 Maven 的基本单位。这是一个 XML 文件。它始终保存在项目基本目录中。

POM 包含的项目是使用 Maven 来构建的,以及它也包含各种配置信息。

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

  • project dependencies
  • plugins
  • goals
  • build profiles
  • project version
  • developers mailing list

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

例子

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.qgzang</groupId>
  <artifactId>Maven_demo</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>Maven_demo</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

应当指出,每个项目应该有一个单一的POM文件。

  • 所有的 POM 文件要项目元素必须三个必填字段: groupId,artifactId,version
  • 在库中的项目符号是:groupId:artifactId:version
  • pom.xml 的根元素是 project,它有三个主要的子节点
节点描述
groupIdThis 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.

超级POM

所有的POM继承自父类(尽管明确界定)。这个基础的 POM 被称为超级POM,并包含继承默认值。 Maven使用有效的POM(超级POM加项目配置的配置)执行有关目标。它可以帮助开发人员指定最低配置的详细信息写在 pom.xml 中。虽然配置可以很容易被覆盖。 一个简单的方法来看看超级POM的默认配置,通过运行下面的命令:mvn help:effective-pom 创建一个 pom.xml 。 在下面的例子中,我们已经创建了一个 pom.xml 在C:\MVN\项目文件夹中。 现在,打开命令控制台,进入包含 pom.xml 文件夹并执行以下 mvn 命令。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值