搜索

此内容没有您所选择的语言版本。

3.3. Create an Aggregate Maven Project

download PDF

Aggregate POM

A complete application typically consists of multiple Maven projects. As the number of projects grows larger, however, it becomes a nuisance to build each project separately. Moreover, it is usually necessary to build the projects in a certain order and the developer must remember to observe the correct build order.
To simplify building multiple projects, you can optionally create an aggregate Maven project. This consists of a single POM file (the aggregate POM), usually in the parent directory of the individual projects. The POM file specifies which sub-projects (or modules) to build and builds them in the specified order.

Parent POM

Maven also supports the notion of a parent POM. A parent POM enables you to define an inheritance style relationship between POMs. POM files at the bottom of the hierarchy declare that they inherit from a specific parent POM. The parent POM can then be used to share certain properties and details of configuration.
Important
The details of how to define and use a parent POM are beyond the scope of this guide, but it is important to be aware that a parent POM and an aggregate POM are not the same thing.

Recommended practice

Quite often, you will see examples where a POM is used both as a parent POM and an aggregate POM. This is acceptable for small, relatively simple applications, but is not recommended. In general, it is better to define separate POM files for the parent POM and the aggregate POM.

Create an aggregate POM

To create an aggregate POM for your getting started application, use a text editor to create a pom.xml file in the get-started directory and add the following contents to the file:
<?xml version="1.0" encoding="UTF-8"?>
<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">
  
  <groupId>org.fusesource.example</groupId>
  <artifactId>get-started</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>pom</packaging>
  <modelVersion>4.0.0</modelVersion>

  <name>Getting Started :: Aggregate POM</name>
  <description>Getting Started example</description>

  
  <modules>
    <module>cxf-basic</module>
    <module>camel-basic</module>
  </modules>
  

</project>
As with any other POM, the groupId, artifactId, and version must be defined, in order to identify this artifact uniquely. But the packaging must be set to pom. The key portion of the aggregate POM is the modules element, which defines the list of Maven sub-projects to build and defines the order in which the projects are built. The content of each module element is the relative path of a directory containing a Maven project.

Building with the aggregate POM

Using the aggregate POM you can build all of sub-projects in one go, by entering the following at a command prompt:
cd get-started
mvn install
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.