Chapter 3. Install and Use the Maven Repositories

3.1. About Maven

Apache Maven is a distributed build automation tool used in Java application development to create, manage, and build software projects. Maven uses standard configuration files called Project Object Model (POM) files to define projects and manage the build process. POM files describe the module and component dependencies, build order, and targets for the resulting project packaging and output using an XML file. This ensures that the project is built correctly and in a uniform manner.

Important

Red Hat JBoss Data Grid requires Maven 3 (or better) for all quickstarts and general use.

Visit the Maven Download page (http://maven.apache.org/download.html) for instructions to download and install Maven.

3.2. Required Maven Repositories

Red Hat JBoss Data Grid Quickstarts require the following Maven repositories to be set up as a prerequisite:

Both Maven repositories are installed in the same way. As a result, the subsequent instructions are for both repositories.

3.3. Install the Maven Repository

3.3.1. Install the Maven Repository

There are three ways to install the required repositories:

  1. On your local file system (Local File System Repository Installation).
  2. On Apache Web Server (Apache httpd Repository Installation).
  3. With a Maven repository manager (Maven Repository Manager Installation).

Use the option that best suits your environment.

3.3.2. Local File System Repository Installation

This option is best suited for initial testing in a small team. Follow the outlined procedure to extract the Red Hat JBoss Data Grid and JBoss Enterprise Application Platform Maven repositories to a directory in your local file system:

Local File System Repository Installation (JBoss Data Grid)

  1. Log Into the Customer Portal

    In a browser window, navigate to the Customer Portal page (https://access.redhat.com/home) and log in.

  2. Download the JBoss Data Grid Repository File

    Download the jboss-datagrid-{VERSION}-maven-repository.zip file from the Red Hat Customer Portal.

  3. Unzip the file to a directory on your local file system (for example $JDG_HOME/projects/maven-repositories/ ).

The above procedure will create a new jboss-datagrid-${jdg-version}-maven-repository directory, which contains the Maven repository in a subdirectory entitled maven-repository/ .

3.3.3. Apache httpd Repository Installation

This example will cover the steps to download the JBoss Data Grid Maven Repository for use with Apache httpd. This option is good for multi-user and cross-team development environments because any developer that can access the web server can also access the Maven repository.

Note

Apache httpd must be configured for the following steps to work. For instructions on configuring Apache refer to the Apache HTTP Server Project.

  1. Open a web browser and access https://access.redhat.com/jbossnetwork/restricted/listSoftware.html?product=data.grid
  2. Find Red Hat JBoss Data Grid 7.2.1 Maven Repository in the list.
  3. Click the Download button to download a .zip file containing the repository.
  4. Unzip the files in a directory that is web accessible on the Apache server.
  5. Configure Apache to allow read access and directory browsing in the created directory.

3.3.4. Maven Repository Manager Installation

This option is ideal if you are already using a repository manager.

The Red Hat JBoss Data Grid and JBoss Enterprise Application Server repositories are installed using a Maven repository manager using its documentation. Examples of such repository managers are:

3.4. Configure the Maven Repository

3.4.1. Configure the Maven Repository

To configure the installed Red Hat JBoss Data Grid Maven repository, edit the settings.xml file. This file may be configured in one of two locations:

  1. User level - Maven user settings are located in the ${user.home}/.m2/ directory:

    • For Linux or Mac environments this is typically ~/.m2/
    • For Windows environments this is typically \Documents and Settings\.m2\ or \Users\.m2\
  2. Global level - Settings for all users on a machine, assuming they are all using the same Maven installation, is typically provided in ${maven.home}/conf/settings.xml

See to view sample Maven configurations, and refer to the Maven Documentation for more information about configuring Maven.

3.4.2. Configuring the JBoss Data Grid Maven Repository in an Offline Environment

In certain environments it is preferred to have the Maven repository available offline.

To accomplish this configuration perform the following steps:

Prerequisites:

  • The Red Hat JBoss Data Grid Maven repository has been downloaded to the internal network where it will be referenced.
  • JBoss Data Grid 7.0 and later depends on the JBoss EAP Maven repository. You should also download this repository to the internal network where it will be referenced.
  • An internal repository, such as Sonatype Nexus or Apache Archiva, is available on the network that contains Maven dependencies.

Configure the JBoss Data Grid Maven Repository for Offline Usage

  1. Install the downloaded JBoss Data Grid Maven repository locally, following the instructions in Local File System Repository Installation.
  2. Update the settings.xml to point to the locally extracted repository, as seen in Configure the Maven Repository. A sample configuration is shown below:

    <?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>
          <profile>
             <id>jboss-datagrid-repository</id>
             <repositories>
                <repository>
                   <id>jboss-datagrid-repository</id>
                   <name>JBoss Data Grid Maven Repository</name>
                   <url>file:///path/to/jboss-datagrid-7.2.0-maven-repository/maven-repository</url>
                   <layout>default</layout>
                   <releases>
                      <enabled>true</enabled>
                      <updatePolicy>never</updatePolicy>
                   </releases>
                   <snapshots>
                      <enabled>false</enabled>
                      <updatePolicy>never</updatePolicy>
                   </snapshots>
                </repository>
             </repositories>
             <pluginRepositories>
                <pluginRepository>
                   <id>jboss-datagrid-repository</id>
                   <name>JBoss Data Grid Maven Repository</name>
                   <url>file:///path/to/jboss-datagrid-7.2.0-maven-repository/maven-repository</url>
                   <layout>default</layout>
                   <releases>
                      <enabled>true</enabled>
                      <updatePolicy>never</updatePolicy>
                   </releases>
                   <snapshots>
                      <enabled>false</enabled>
                      <updatePolicy>never</updatePolicy>
                   </snapshots>
                </pluginRepository>
             </pluginRepositories>
          </profile>
       </profiles>
       <activeProfiles>
          <!-- make the profile active by default -->
          <activeProfile>jboss-datagrid-repository</activeProfile>
       </activeProfiles>
    
    </settings>
  3. Ensure that projects may now be built locally.

3.4.3. Next Steps

After the newest available version of Red Hat JBoss Data Grid is installed and Maven is set up and configured, see to learn how to use JBoss Data Grid for the first time.

3.5. Maven Transitive Dependencies

When building projects with Maven it will discover and download the dependencies of any included libraries. These additional libraries are referred to as Transitive, or Transient, Dependencies, and are discussed in Maven’s documentation at Transitive Dependencies.

As JBoss Data Grid jar files contain all necessary dependencies to use the product, it is possible to have the same dependency included multiple times if both these jars and individual JBoss Data Grid Maven artifact(s) are specified.

To prevent this issue only one of the following should be used per Maven project:

  • Use the included uberjars, infinspan-embedded and infinispan-remote as the only dependency for JBoss Data Grid. Defining the uberjar will pull in all necessary components for that distribution (Library or Remote Client-Server Mode), and instructions for including these dependencies are found in Run JBoss Data Grid With Maven.
  • Use the individual components from JBoss Data Grid, such as infinispan-core. Each component should either be defined in the parent pom.xml, or be a dependency of a defined component.

Alternatively, if the individual components are known they may be excluded. The following example assumes that infinispan-core is being included twice; once from a defined dependency and the second time as a transient dependency.

...
<dependencies>
  <dependency>
    <groupId>org.infinispan</groupId>
    <artifactId>infinispan-embedded</artifactId>
    <version>${infinispan.version}</version>
    <scope>compile</scope>
    <exclusions>
      <exclusion>  <!-- declare the exclusion here -->
        <groupId>org.infinispan</groupId>
        <artifactId>infinispan-core</artifactId>
      </exclusion>
    </exclusions>
  </dependency>
</dependencies>
...