Red Hat Training

A Red Hat training course is available for Red Hat Fuse

Chapter 6. Maven Repositories

6.1. About Maven

Apache Maven is a distributed build automation tool used in Java application development to build and manage software projects. Maven uses configuration XML files called POM (Project Object Model) to define project properties and manage the build process. POM files describe the project's module and component dependencies, build order, and targets for the resulting project packaging and output. This ensures that projects are built in a correct and uniform manner.
Maven uses repositories to store Java libraries, plug-ins, and other build artifacts. Repositories can be either local or remote. A local repository is a download of artifacts from a remote repository cached on a local machine. A remote repository is any other repository accessed using common protocols, such as http:// when located on an HTTP server, or file:// when located on a file server. The default repository is the public remote Maven 2 Central Repository.
Configuration of Maven is performed by modifying the settings.xml file. You can either configure global Maven settings in the M2_HOME/conf/settings.xml file, or user-level settings in the USER_HOME/.m2/settings.xml file.
For more information about Maven, see Welcome to Apache Maven.
For more information about Maven repositories, see Apache Maven Project - Introduction to Repositories.
For more information about Maven POM files, see the Apache Maven Project POM Reference.

Note

Red Hat JBoss Fuse Service Works has been built with maven 3.0.x Therefore, this is the recommended maven version for building your own SwitchYard applications.

6.2. About The Provided Maven Repositories

A set of repositories containing artifacts required to build applications based on Red Hat JBoss Fuse Service Works is provided with this release. Maven must be configured to use these repositories and the Maven Central Repository in order to provide correct build functionality.
Two interchangeable sets of repositories ensuring the same functionality are provided. The first set is available for download and storage in a local file system, the second set is hosted online for use as remote repositories. If you provided the location of Maven's settings.xml file during installation, Maven is already configured to use the online repositories. If you did not provide the location during installation, you need to configure Maven manually by following the procedure in Section 6.4, “Configuring Maven to Use the Online Repositories” or Section 6.3, “Configuring Maven to Use the File System Repositories”.

Important

The set of online remote repositories is a technology preview source of components. As such, it is not in scope of patching and is supported only for use in development environment. Using the set of online repositories in production environment is a potential source of security vulnerabilities and is therefore not a supported use case. For more information see https://access.redhat.com/site/maven-repository.

6.3. Configuring Maven to Use the File System Repositories

Overview

In situations where you cannot use the online repositories, you will have to download and configure the required repositories locally.

Procedure 6.1. 

  1. Download the following ZIP archives containing the required repositories:

    Note

    Alternatively, the ZIP archives can be downloaded from http://access.redhat.com/jbossnetwork/.
  2. Unzip the downloaded ZIP files into an arbitrary location in a local file system.
  3. Add entries for the unzipped repositories to Maven's settings.xml file. The following code sample contains a profile with the repositories and an activation entry for the profile:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <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/xsd/settings-1.0.0.xsd">
      <localRepository/>
      <profiles>
        <!-- Profile with local repositories required by Fuse Service Works -->
        <profile>
          <id>fsw-local-repos</id>
          <repositories>
            <repository>
              <id>fsw-6.0.0.GA-redhat-2-repository</id>
              <name>FSW 6.0.0.GA Repository</name>
              <url>file://<!-- path to the repository -->/fsw-6.0.0.GA-redhat-2-repository</url>
              <layout>default</layout>
              <releases>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
              </releases>
              <snapshots>
                <enabled>false</enabled>
                <updatePolicy>never</updatePolicy>
              </snapshots>
            </repository>
            <repository>
              <id>jboss-eap-6.1.1.GA-maven-repository</id>
              <name>EAP 6.1.1.GA Repository</name>
              <url>file://<!-- path to the repository -->/jboss-eap-6.1.1.GA-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>fsw-6.0.0.GA-redhat-2-repository</id>
              <name>FSW 6.0.0.GA Repository</name>
              <url>file://<!-- path to the repository -->/fsw-6.0.0.GA-redhat-2-repository</url>
              <layout>default</layout>
              <releases>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
              </releases>
              <snapshots>
                <enabled>false</enabled>
                <updatePolicy>never</updatePolicy>
              </snapshots>
            </pluginRepository>
            <pluginRepository>
              <id>jboss-eap-6.1.1.GA-maven-repository</id>
              <name>EAP 6.1.1 GA Repository</name>
              <url>file://<!-- path to the repository -->/jboss-eap-6.1.1.GA-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>
       <!-- Activation of the Fuse Service Works profile -->
       <activeProfile>fsw-local-repos</activeProfile>
      </activeProfiles>
    </settings>

Important

The bpm-service quickstart application will not build without two additional repositories. If you want to build this application, download the following repositories and add them to your setting.xml file in the same way as that shown above.
Result

The Maven repositories are downloaded, unzipped in a local file system, registered in Maven's settings.xml file, and ready to be used when performing Maven builds.

Troubleshooting

Q: Why does the bpm-service quickstart application fail on build?
Q: Why do I still get errors when building or deploying my applications?
Q: Why is JBoss Developer Studio using my old Maven configuration?
Q:
Why does the bpm-service quickstart application fail on build?
A:
Issue

When you build or deploy the bpm-service quickstart application, it fails with the following error:

[ERROR] Failed to execute goal on project switchyard-quickstart-bpm-service: Could not resolve dependencies for project org.switchyard.quickstarts:switchyard-quickstart-bpm-service:jar:1.1.1-p5-redhat-1: The following artifacts could not be resolved: org.jboss.netty:netty:jar:3.2.6.Final-redhat-2, org.apache.lucene:lucene-queryparser:jar:3.6.2-redhat-4: Could not find artifact org.jboss.netty:netty:jar:3.2.6.Final-redhat-2 in fsw-6.0.0.GA-redhat-2-repository (file:///home/belong/maven_repos/fsw-6.0.0.GA-redhat-2-repository) -> [Help 1]
Cause

The bpm-service quickstart application requires an additional two dependencies, provided by the JBoss EAP 6.0.1 and JBoss Web Framework Kit 2.5.0 Maven repositories.

Resolution

  1. Download the following ZIP archives, and unzip them into a location of your choice:
  2. Add entries for the unzipped repositories to your Maven settings.xml file:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <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/xsd/settings-1.0.0.xsd">
      <localRepository/>
      <profiles>
        <!-- Profile with local repositories required by Fuse Service Works -->
        <profile>
          <id>fsw-local-repos</id>
          <repositories>
            <repository>
              <id>fsw-6.0.0.GA-redhat-2-repository</id>
              <name>FSW 6.0.0.GA Repository</name>
              <url>file://<!-- path to the repository -->/fsw-6.0.0.GA-redhat-2-repository</url>
              <layout>default</layout>
              <releases>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
              </releases>
              <snapshots>
                <enabled>false</enabled>
                <updatePolicy>never</updatePolicy>
              </snapshots>
            </repository>
            <repository>
              <id>jboss-eap-6.1.1.GA-maven-repository</id>
              <name>EAP 6.1.1.GA Repository</name>
              <url>file://<!-- path to the repository -->/jboss-eap-6.1.1.GA-maven-repository</url>
              <layout>default</layout>
              <releases>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
              </releases>
              <snapshots>
                <enabled>false</enabled>
                <updatePolicy>never</updatePolicy>
              </snapshots>
            </repository>
            <repository>
              <id>jboss-wfk-2.5.0-maven-repository</id>
              <name>JBoss WFK 2.5.0 Repository</name>
              <url>file://<!-- path to the repository -->/jboss-wfk-2.5.0-maven-repository</url>
              <layout>default</layout>
              <releases>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
              </releases>
              <snapshots>
                <enabled>false</enabled>
                <updatePolicy>never</updatePolicy>
              </snapshots>
            </repository>
            <repository>
              <id>jboss-eap-6.0.1-maven-repository</id>
              <name>EAP 6.0.1 Repository</name>
              <url>file://<!-- path to the repository -->/jboss-eap-6.0.1-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>fsw-6.0.0.GA-redhat-2-repository</id>
              <name>FSW 6.0.0.GA Repository</name>
              <url>file://<!-- path to the repository -->/fsw-6.0.0.GA-redhat-2-repository</url>
              <layout>default</layout>
              <releases>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
              </releases>
              <snapshots>
                <enabled>false</enabled>
                <updatePolicy>never</updatePolicy>
              </snapshots>
            </pluginRepository>
            <pluginRepository>
              <id>jboss-eap-6.1.1.GA-maven-repository</id>
              <name>EAP 6.1.1 GA Repository</name>
              <url>file://<!-- path to the repository -->/jboss-eap-6.1.1.GA-maven-repository</url>
              <layout>default</layout>
              <releases>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
              </releases>
              <snapshots>
                <enabled>false</enabled>
                <updatePolicy>never</updatePolicy>
              </snapshots>
            </pluginRepository>
            <pluginRepository>
              <id>jboss-wfk-2.5.0-maven-repository</id>
              <name>JBoss WFK 2.5.0 Repository</name>
              <url>file://<!-- path to the repository -->/jboss-wfk-2.5.0-maven-repository</url>
              <layout>default</layout>
              <releases>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
              </releases>
              <snapshots>
                <enabled>false</enabled>
                <updatePolicy>never</updatePolicy>
              </snapshots>
            </pluginRepository>
            <pluginRepository>
              <id>jboss-eap-6.0.1-maven-repository</id>
              <name>EAP 6.0.1 Repository</name>
              <url>file://<!-- path to the repository -->/jboss-eap-6.0.1-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>
       <!-- Activation of the Fuse Service Works profile -->
       <activeProfile>fsw-local-repos</activeProfile>
      </activeProfiles>
    </settings>

Q:
Why do I still get errors when building or deploying my applications?
A:
Issue

When you build or deploy a project, it fails with one or both of the following errors:

  • [ERROR] Failed to execute goal on project PROJECT_NAME
  • Could not find artifact ARTIFACT_NAME

Cause

Your cached local Maven repository might contain outdated artifacts.

Resolution

To resolve the issue, delete the cached local repository – the ~/.m2/repository/ directory on Linux or the %SystemDrive%\Users\USERNAME\.m2\repository\ directory on Windows – and run mvn clean install -U. This will force Maven to download correct versions of required artifacts when performing the next build.

Q:
Why is JBoss Developer Studio using my old Maven configuration?
A:
Issue

You have updated your Maven configuration, but this configuration is not reflected in JBoss Developer Studio.

Cause

If JBoss Developer Studio is running when you modify your Maven settings.xml file, this configuration will not be reflected in JBoss Developer Studio.

Resolution

Refresh the Maven settings in the IDE. From the menu, choose WindowPreferences. In the Preferences Window, expand Maven and choose User Settings. Click the Update Settings button to refresh the Maven user settings in JBoss Developer Studio.
Update Maven User Settings

Figure 6.1. Update Maven User Settings

6.4. Configuring Maven to Use the Online Repositories

The online repositories required for Red Hat JBoss Fuse Service Works applications are located at http://maven.repository.redhat.com/techpreview/all/ and http://repository.jboss.org/nexus/content/repositories/public/.
If you provided the location of Maven's settings.xml file during installation, Maven is already configured to use the online repositories. If you did not provide the location during installation, you need to configure Maven manually by following the procedure in Section 6.4, “Configuring Maven to Use the Online Repositories” or Section 6.3, “Configuring Maven to Use the File System Repositories”.
If you did not configure the Maven repository during installation, you can configure it using the following procedure. (It is also possible to do this using the project's POM file, but this is not recommended.)

Procedure 6.2. Configuring Maven to Use the Online Repositories

  1. Add entries for the online repositories to Maven's settings.xml file as in the code sample below:
    <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 with online repositories required by Fuse Service Works -->
        <profile>
          <id>fsw-online-repos</id>
          <repositories>
            <repository>
              <id>jboss-ga-repository</id>
              <url>http://maven.repository.redhat.com/techpreview/all</url>
              <releases>
                <enabled>true</enabled>
              </releases>
              <snapshots>
                <enabled>false</enabled>
              </snapshots>
            </repository>
            <repository>
              <id>jboss-public-repository</id>
              <url>http://repository.jboss.org/nexus/content/repositories/public/</url>
              <releases>
                <enabled>true</enabled>
              </releases>
              <snapshots>
                <enabled>false</enabled>
              </snapshots>
            </repository>
          </repositories>
          <pluginRepositories>
            <pluginRepository>
              <id>jboss-ga-plugin-repository</id>
              <url>http://maven.repository.redhat.com/techpreview/all</url>
              <releases>
                <enabled>true</enabled>
              </releases>
              <snapshots>
                <enabled>false</enabled>
              </snapshots>
            </pluginRepository>
            <pluginRepository>
              <id>jboss-public-plugin-repository</id>
              <url>http://repository.jboss.org/nexus/content/repositories/public/</url>
              <releases>
                <enabled>true</enabled>
              </releases>
              <snapshots>
                <enabled>false</enabled>
              </snapshots>
            </pluginRepository>
          </pluginRepositories>
        </profile>    
      </profiles>
    
      <activeProfiles>
        <!-- Activation of the Fuse Service Works profile -->
        <activeProfile>fsw-online-repos</activeProfile>
      </activeProfiles>
    
    </settings>
  2. If you modified the settings.xml file while JBoss Developer Studio was running, you must refresh Maven settings in the IDE. From the menu, choose WindowPreferences. In the Preferences Window, expand Maven and choose User Settings. Click the Update Settings button to refresh the Maven user settings in JBoss Developer Studio.
    Update Maven User Settings

    Figure 6.2. Update Maven User Settings

Result

Maven has been configured to use the online repositories provided for Red Hat JBoss Fuse Service Works.

Important

If your cached local Maven repository contains outdated artifacts, you may encounter one of the following Maven errors when you build or deploy your project:
  • Missing artifact ARTIFACT_NAME
  • [ERROR] Failed to execute goal on project PROJECT_NAME; Could not resolve dependencies for PROJECT_NAME
To resolve the issue, delete the cached local repository – the ~/.m2/repository/ directory on Linux or the %SystemDrive%\Users\USERNAME\.m2\repository\ directory on Windows. This will force Maven to download correct versions of required artifacts during the next build.

6.5. Dependency Management

In order to use correct Maven dependencies in your Red Hat JBoss Fuse Service Works project, relevant Bill Of Materials (BOM) and parent POM files must be added to the project's pom.xml file. Adding the BOM and parent will ensure that correct versions of plugins and transitive dependencies from the provided Maven repositories are included in the project.
To ensure correct dependency usage in your project, declare the following parent in the project's pom.xml file:
  • org.jboss.ip.component.management:ip-parent:1.1-redhat-5
and add the following two BOM files as dependencies in the dependencyManagement section:
  • org.jboss.ip.component.management:ip-dependency-management-all:1.1-redhat-5
  • org.jboss.component.management:jboss-dependency-management-all:6.1.1.Final-redhat-61
Use the entries from the code sample below for this purpose.
<parent>
  <groupId>org.jboss.ip.component.management</groupId>
  <artifactId>ip-parent</artifactId>
  <version>1.1-redhat-5</version>
</parent>

...

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.jboss.ip.component.management</groupId>
      <artifactId>ip-dependency-management-all</artifactId>
      <type>pom</type>
      <version>1.1-redhat-5</version>
      <scope>import</scope>
    </dependency>
    <dependency>
      <groupId>org.jboss.component.management</groupId>
      <artifactId>jboss-dependency-management-all</artifactId>
      <type>pom</type>
      <version>6.1.1.Final-redhat-61</version>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>