Appendix B. Introduction to Apache Maven
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
-
The schema for the
pom.xml
file is available at http://maven.apache.org/maven-v4_0_0.xsd. - For more information about POM files, see the Apache Maven Project POM Reference.
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.5 Java packages and dependencies.
Additional resources
- For more information about Maven repositories, see Introduction to Repositories.
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 asglobal
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 usersettings.xml
files exist, the contents are merged. Where there are overlaps, the user’ssettings.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
-
The schema for the
settings.xml
file is available at http://maven.apache.org/xsd/settings-1.0.0.xsd. - For more information about the Maven settings file, see the Settings Reference.
Revised on 2019-10-09 14:21:52 UTC