Search

Appendix B. Introduction to Apache Maven

download PDF

Apache Maven is a distributed build automation tool used in Java application development to create, manage, and build software projects. You use it to run the AMQ Broker example programs that are included with the AMQ Broker installation.

Running the AMQ Broker example programs requires you to interact with several Maven components:

Project object model (POM) files
Store information about how the project should be built.
Repositories
Hold build artifacts and dependencies.
The Maven settings file
Stores user-specific configuration information.

B.1. Maven POM files

Maven uses standard configuration files called Project Object Model (POM) files to define projects and manage the build process. They ensure that the project is built correctly and uniformly. POM files are XML files (pom.xml).

Maven favors "convention over configuration". Therefore, POM files require minimal configuration and default all other values. A POM file can define the following information for a Maven project:

  • Location of the source, test, and target directories
  • Project dependencies
  • Plug-in repositories
  • Goals that the project can execute
  • Additional details about the project, such as the version, description, developers, mailing list, license, and so on.

Example B.1. Sample pom.xml file

This basic pom.xml file demonstrates the minimum requirements for a POM file:

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.jboss.app</groupId>
  <artifactId>my-app</artifactId>
  <version>1</version>
</project>

Additional Resources

B.2. Maven repositories

A Maven repository stores Java libraries, plugins, and other build artifacts. Repositories can be either local or remote.

The default public repository is the Maven 2 Central Repository, but repositories can be private and internal within a company so that common artifacts can be shared among development teams.

Repositories are also available from third-parties. AMQ includes a Maven repository that contains tested and supported versions of the AMQ 7.9 Java packages and dependencies.

Additional resources

B.3. The Maven settings file

The Maven settings.xml file contains user-specific configuration information for Maven. It contains information that must not be distributed with the pom.xml file, such as developer identity, proxy information, local repository location, and other settings specific to a user.

The settings.xml file is found in two locations:

  • In the Maven installation:

    The settings.xml file is located in the <maven-install-dir>/conf/ directory. These settings are referred to as global settings. The default Maven settings file is a template that you can copy and use as a starting point for the user settings file.

  • In the user’s installation:

    The settings.xml file is located in the ${user.home}/.m2/ directory. If both the Maven and user settings.xml files exist, the contents are merged. Where there are overlaps, the user’s settings.xml file takes precedence.

Example B.2. The Maven settings file

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <profiles>
    <!-- Configure the JBoss AMQ Maven repository -->
    <profile>
      <id>jboss-amq-maven-repository</id>
      <repositories>
        <repository>
          <id>jboss-amq</id>
          <url>file:///path/to/repo/</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>jboss-amq-maven-plugin-repository</id>
          <url>file://path/to/repo</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <activeProfiles>
    <!-- Optionally, make the repository active by default -->
    <activeProfile>jboss-amq-maven-repository</activeProfile>
  </activeProfiles>
</settings>

Additional resources

Revised on 2022-03-22 15:27:27 UTC

Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.