Maven protocol (via URIs starting with mvn:) enables you access to maven repository artifacts based on well known by now groupId, artifactId, version, type and classifier.

For low level details, please see information in Maven Guide.

There are three kinds of repositories involved (in the order of access):

Aether library (used internally by pax-url-aether) has only the concept of local and remote repository. Default repository is pax-url-aether library concepts that makes configuration clearer.

There's important consequence of the above separation:

In the process of resolving the artifact, the handler will make use of local repository if possible or any set of remote repositories including existing metadata for resolving latest of a snapshot version.

To use the mvn url handler is not required to have maven installed on the machine that runs the osgi framework. Having maven installed will actually only have an impact on the download speed as if the referenced artifacts are already in the local repository, case when those artifacts will be used as opposite of going over the net and download them from a remote repository.

Syntax ( see #examples )

mvn-uri := 'mvn:' [ repository-url '!' ] group-id '/' artifact-id [ '/' [version] [ '/' [type] [ '/' classifier ] ] ] ]
repository-url := < rfc2396 uri > ; an url that points to a maven 2 repository
group-id := < maven groupId > ; group id of maven artifact
artifact-id := < maven artifactId > ; artifact id of maven artifact
version := < maven version > | 'LATEST' | range ; version of maven artifact
range := ( '[' | '(' ) version ',' version ( ')' | ']' )
type := < maven type> ; type of maven artifact
classifier := < maven classifier> ; maven artifact classifier
Notes

Version range (starting with version 0.2.0)

If the version is specified as a range, the version will be resolved by first resolving all versions for that artifact from all available repositories. Then the version with the higher version number that can be downloaded will be used. The square brackets denotes an inclusive range and the rounded brackets denote an exclusive range.
For example mvn:commons-logging/commons-logging/[1.0,1.1) will be resolved as version 1.0.4 as being the highest version that fits the range.
Here are some examples, where x is a version that is found in maven metadata:

Note that the versions from local repository (beside snapshot versions) are not taken in consideration as Maven does not create metadata for them. This maybe solved in the future by actually scanning the local repository directory to determine the versions.

Maven proxies (starting with version 0.3.2)

Detailed configuration of HTTP proxies used during Maven resolution is described in HTTP Proxies.

Read more about Maven proxies here.

With pax-url-aether 2.3.0, HTTP proxy configuration was totally rewritten. Before 2.3.0, pax-url-aether used wagon-http-lightweight library that had issues with proxies (affecting JVM-wide configuration using system properties). With version 2.3.0, wagon-http and Apache HTTP Client libraries are used.

Configuration

The service can be configured in two ways: via configuration admin if available and via framework/system properties where the configuration via config admin has priority.

In other words, when pax-url-aether starts it checks whether Configuration Admin is available. If no, then properties available from BundleContext (configured e.g., inside etc/config.properties of Karaf) are used. When Configuration Admin becomes available, configuration with org.ops4j.pax.url.mvn PID is used.

This may be cause of subtle problems. pax-url-aether may be started before Configuration Admin is available. If Maven resolution is performed very early in the lifetime of OSGi runtime and if proper configuration is available only in etc/org.ops4j.pax.url.mvn.cfg then there may be short period of time where pax-url-aether is improperly configured. The solution is to duplicate the configuration in etc/config.properties as well.

Configuration options are described in more details in Aether Configuration. Here's a brief summary of options (properties in org.ops4j.pax.url.mvn PID or in etc/config.properties file when/while Configuration Admin service is not (yet) available.

Option key

Description

Since
org.ops4j.pax.url.mvn.defaultRepositoriesoptional; a comma separated list for default repositories urls; see below
org.ops4j.pax.url.mvn.repositoriesoptional; a comma separated list for remote repositories urls; see below
org.ops4j.pax.url.mvn.localRepositoryoptional; the path to local repository directory; see below
org.ops4j.pax.url.mvn.useFallbackRepositoriesoptional; whether http://repo1.maven.org/maven2 should be used as one of implicit remote repositories
org.ops4j.pax.url.mvn.settingsoptional; the path to settings.xml; see below
org.ops4j.pax.url.mvn.globalChecksumPolicyoptional; policy for handling checksums
org.ops4j.pax.url.mvn.globalUpdatePolicyoptional; remote maven repository update policy; see github

org.ops4j.pax.url.mvn.defaultLocalRepoAsRemote

optional; true/false if local repository should be used as first, implicit remote repository. Should always be false.


org.ops4j.pax.url.mvn.certificateCheckoptional; true/false if the SSL certificate check should be done. Default false.

org.ops4j.pax.url.mvn.proxySupport

optional; true/false if the proxy support is enabled . Default true.


org.ops4j.pax.url.mvn.timeouttimeout set for socket connection and read operations; used when socket.readTimeout or socket.connectionTimeout are not defined
org.ops4j.pax.url.mvn.socket.readTimeoutdedicated option for setting read timeout when accessing remote repositories2.5.0
org.ops4j.pax.url.mvn.socket.connectionTimeoutdedicated option for setting connection timeout when accessing remote repositories2.5.0

org.ops4j.pax.url.mvn.socket.linger

SO_LINGER option for sockets (see details here, default value is -1)2.5.0
org.ops4j.pax.url.mvn.socket.reuseAddressSO_REUSEADDDR option for sockets (see details here, default value is false)2.5.0
org.ops4j.pax.url.mvn.socket.tcpNoDelayTCP_NODELAY option for sockets (see details here, default value is true)2.5.0
org.ops4j.pax.url.mvn.socket.keepAliveSO_KEEPALIVE option for sockets (see details here, default value is false)2.5.0
org.ops4j.pax.url.mvn.connection.bufferSizebuffer size (read and write buffers) used by Apache httpclient when accessing remote repositories (default value is 8192)2.5.0
org.ops4j.pax.url.mvn.connection.retryCountconfiguration option for Apache httpclient's DefaultHttpRequestRetryHandler (default value is 3)2.5.0

Settings.xml

Detailed information about settings.xml usage is described in settings.xml.

If necessary the handler will make use if possible of maven settings.xml using the following resolution:

  1. looks for a configuration property org.ops4j.pax.url.mvn.settings
  2. if not found looks for ${user.home}/.m2/settings.xml
  3. if not found looks for ${maven.home}/conf/settings.xml
  4. if not found looks for ${M2_HOME}/conf/settings.xml

Local repository

The local repository will be resolved by using the following resolution:

  1. looks for a configuration property org.ops4j.pax.url.mvn.localRepository;
  2. looks in settings.xml for <localRepository> element);
  3. falls back to ${user.home}/.m2/repository.

As described earlier, local repository is used to store artifacts downloaded from remote repositories. Further resolutions of the same artifact won't require external repository access if the artifact is available in local repository.

Repositories

org.ops4j.pax.url.repositories is a comma separated list of remote repositories to be used when artifact needs to be resolved/retrieved, but it's not available in both default repositories and local repository. An @id is required for all URLs otherwise it will be ignored (e.g., http://repository.ops4j.org/mvn-snapshots@snapshots@id=ops4j-snapshot). If repository access requests authentication the user name and password must be specified in the repository URL as for example http://user:password@repository.ops4j.org/maven2.

If the repositories from configuration starts with a plus sign ("+"), the option 2 is also used and the repositories from settings.xml will be appended to the list.
Repositories resolution:

  1. looks for a org.ops4j.pax.url.mvn.repositories configuration property,
  2. looks in settings.xml for <repository> elements. Only repositories from active profiles are considered. Before pax-url-aether 2.5.0, active profiles were those explicitly specified in <activeProfiles>/<activeProfile>. Version 2.5.0 also takes into account those profiles that have <activation>/<activeByDefault> set to true. These repositories are appended to the list of original repositories from org.ops4j.pax.url.mvn.repositories, if the value of this option starts with "+"
  3. if org.ops4j.pax.url.mvn.defaultLocalRepoAsRemote is set to true (not recommended!), local repository is used as first remote repository.

Here's the example:

<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>development</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <repositories>
        <repository>
          <id>ops4j-snapshot</id>
          <name>ops4j.org snapshot repository</name>
          <url>http://repository.ops4j.org/mvn-snapshots/</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
        <repository>
          <id>ops4j</id>
          <name>ops4j.org release repository</name>
          <url>http://repository.ops4j.org/maven2/</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </repository>
        <repository>
          <id>ops4j-runner-snapshot</id>
          <name>ops4j.org pax runner snapshot repository</name>
          <url>http://scm.ops4j.org/repos/ops4j/projects/pax/runner-repository</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
      <pluginRepositories>
        <!-- for a version that fixes PAXEXAM-159 and 160 -->
        <pluginRepository>
          <id>ops4j-plugin-snapshot</id>
          <name>ops4j.org snapshot repository</name>
          <url>http://repository.ops4j.org/mvn-snapshots/</url>
        </pluginRepository>
        <pluginRepository>
          <id>apache-plugin-snapshot</id>
          <name>apache.org snapshot repository</name>
          <url>http://repository.apache.org/content/groups/snapshots-group</url>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>development</activeProfile>
  </activeProfiles>
</settings>

Marking repositories as containing releases / snapshots (starting with release 0.2.1)

Usually repositories (not local repository) contains either releases or snapshot artifacts. In order to speed up the artifact locations discovery you can mark the repository with the type of artifacts it contains. This is similar with setting the release/enabled / snapshots/enabled tags in pom.xml or settings.xml.

By default (no marking) the local repository is considered as containing both releases and snapshots and the other repositories as containing only releases (same behavior as Maven).

You can alter this default behavior by adding the following to repository url (not case sensitive):

You can add this markings in any order and you can add them both to an url. Here are some examples:

http://repository.ops4j.org ; default no markings: searched only for releases, no snapshots
http://repository.ops4j.org/mvn-snapshots@snapshots ; searched for releases and snapshots
http://repository.ops4j.org/mvn-snapshots@snapshots@noreleases ; searched snapshots, no releases

Default repositories (starting with release 0.3.3)

In some cases, it may be useful to have more control of the list of repositories used to avoid the user settings to affect the download of artifacts. This can be done by configuring the defaultRepositories property to a list of repositories URLs. If this property is defined, the configured repositories will be checked first, before checking the local repository and other remote repositories configured using the repositories property. This property is available for pax-url >= 0.3.3.

Repository options

When specifying URI on a org.ops4j.pax.url.mvn.repositories list, we may use the following format:

http(s)://host:port/path@snapshots@noreleases@id=ID@other_options


Options that may be specified are:

Remember, that global policies (either for checksums or updates) are always preferred over the ones specified at repository URI level!

Examples

Refers to version 0.2.0 of Pax Web that will be resolved from local repository and optionaly other repositories configured in #settings.xml

mvn:org.ops4j.pax.web.bundles/service/0.2.0 - an artifact that will be resolved based on the configured repositories

Refers to latest version of Pax Web that will be resolved from local repository and optionaly other repositories configured in #settings.xml

mvn:org.ops4j.pax.web.bundles/service
mvn:org.ops4j.pax.web.bundles/service/LATEST

Refers to snapshot version of Pax Web that will be resolved from local repository and optionaly other repositories configured in #settings.xml

mvn:org.ops4j.pax.web.bundles/service/0.2.0-SNAPSHOT

Refers to version 0.2.0 of Pax Web from OPS4J repository. Only the specified repository will not be used during resolution.

mvn:http://repository.ops4j.org/maven2!org.ops4j.pax.web.bundles/service/0.2.0

- an artifact from an http repository

Refers to version 0.2.0 of Pax Web from OPS4J repository; the user / password will be used for authentication if required. Only the specified repository will not be used during resolution.

mvn:http://user:password@repository.ops4j.org/maven2!org.ops4j.pax.web.bundles/service/0.2.0

Refers to version 0.2.0 of Pax Web from a repository starting at c:/localRepo. Only the specified repository will not be used during resolution.

mvn:file://c:/localRepo!org.ops4j.pax.web.bundles/service/0.2.0 - an artifact from a directory

Refers to version 0.2.0 of Pax Web from a repository packed in a zip file. Only the specified repository will not be used during resolution.

 mvn:jar:file://c:/repo