Red Hat Training

A Red Hat training course is available for Red Hat Fuse

4.3. Locating Maven Artifacts at Run Time

Overview

At run time the container strikes a balance between accessing artifacts locally and downloading artifacts from remote repositories. The container will first search all systems local to the container. If it cannot locate the artifacts in a local repository, it will then search remote repositories.
For default features, the artifacts are always stored in the container's system repository. For non-default features, third party bundles, or customer developed bundles, it is likely that Maven will need to search remote repositories to locate the artifacts.

Procedure for locating artifacts

Figure 4.2, “How the Container Locates Artifacts at Run Time” shows an overview of the procedure that Red Hat JBoss Fuse follows when a feature or bundle is installed at run time.

Figure 4.2. How the Container Locates Artifacts at Run Time

The steps followed to locate the required Maven artifacts are:
  1. The container searches for artifacts in the system repository.
    This repository contains all of the artifacts provided with the JBoss Fuse installation. The system repository is located at EsbInstallDir/system.
  2. If an artifact is not available in the system repository, the container searches any other configured default repositories.
    JBoss Fuse allows you to specify one or more repositories into which you can place artifacts. For example, you could use a shared folder as a default repository that provides an easy way to distribute bundles to remote machines. See the section called “Default repositories” for details on configuring the default repositories.
  3. If the artifact is not available in the default repositories, the container searches the Maven local repository.
    The default location of the local repository is the .m2/repository/ directory under the user's home directory. See the section called “Local repository” for details on configuring the local repository.
  4. If the artifact is not available in any of the local repositories, the container searches the remote repositories specified in the JBoss Fuse configuration.
    The remote repositories are specified by the org.ops4j.pax.url.mvn.repositories property in the org.ops4j.pax.url.mvn. PID. See the section called “Remote repositories” for details on configuring the remote repositories that the container will check.
    Note
    If an artifact is found in a remote repository, it is automatically downloaded and installed into the local repository.

Default repositories

The default repositories are a list of repositories that the container always checks first. The list is specified by the org.ops4j.pax.url.mvn.defaultRepositories in the org.ops4j.pax.url.mvn PID. The property's initial setting is a single entry for the container's system repository as shown in Example 4.1, “Initial Setting for a Container's Default Repositories”.

Example 4.1. Initial Setting for a Container's Default Repositories

org.ops4j.pax.url.mvn.defaultRepositories=file:${karaf.home}/${karaf.default.repository}@snapshots
The org.ops4j.pax.url.mvn.defaultRepositories property is a comma-separated list, so you can specify multiple default repositories. You can specify the repository location using a URL with a file:, http:, or https: scheme. You can optionally add the following suffixes to the URL:
  • @snapshots—allow snapshot versions to be read from the repository
  • @noreleases—do not allow release versions to be read from the repository
Note
It is recommended that you leave the container's system repository as the first entry in the list.

Local repository

The container resolves the location of the local repository in the following manner:
  1. Use the location specified by the org.ops4j.pax.url.mvn.localRepository.localRepository property in the org.ops4j.pax.url.mvn PID.
  2. Otherwise, use the location specified by the localRepository element in the settings.xml file specified by the org.ops4j.pax.url.mvn.localRepository.settings property in the org.ops4j.pax.url.mvn PID.
  3. Otherwise, use the location specified by the localRepository element in the .m2/settings.xml file located under the user's home directory.
  4. Otherwise, use the location specified by the localRepository element in the M2_HOME/conf/settings.xml file.
  5. Otherwise, the default location is .m2/repository/ under the user's home directory.

Remote repositories

The remote repositories checked by the container are specified by the org.ops4j.pax.url.mvn.repositories property in the org.ops4j.pax.url.mvn PID. The repositories are specified as a comma-separated list as shown in Example 4.2, “Setting a Container's Remote Repositories”.

Example 4.2. Setting a Container's Remote Repositories

org.ops4j.pax.url.mvn.repositories= \
    http://repo1.maven.org/maven2, \
    http://repo.fusesource.com/maven2, \
    http://repo.fusesource.com/maven2-snapshot@snapshots@noreleases, \
    http://repo.fusesource.com/nexus/content/repositories/releases, \
    http://repo.fusesource.com/nexus/content/repositories/snapshots@snapshots@noreleases, \
    http://repository.apache.org/content/groups/snapshots-group@snapshots@noreleases, \
    http://repository.ops4j.org/maven2, \
    http://svn.apache.org/repos/asf/servicemix/m2-repo, \
    http://repository.springsource.com/maven/bundles/release, \
    http://repository.springsource.com/maven/bundles/external
You can optionally add the following suffixes to the URsL:
  • @snapshots—allow snapshot versions to be read from the repository
  • @noreleases—do not allow release versions to be read from the repository