Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

This plugin for Maven 2 is based on the BND tool from Peter Kriens. The way BND works is by treating your project as a big collection of classes (e.g., project code, dependencies, and the class path). The way you create a bundle with BND is to tell it the content of the bundle's JAR file as a subset of the available classes. This plugin wraps BND to make it work specifically with the Maven 2 project structure and to provide it with reasonable default behavior for Maven 2 projects.

...

Since the 1.4.0 release, this plugin also aims to automate OBR (OSGi Bundle Repository) management. It helps manage a local OBR for your local Maven repository, and also supports remote OBRs for bundle distribution. The plug-in automatically computes bundle capabilities and requirements, using a combination of Bindex and Maven metadata.

Tip

Standard Maven Documentation is now available for maven-bundle-plugin 2.3.7

Tip

A complete list of instructions and their format is available from the BND website

Anchor
simple-example
simple-example

...

  • <Bundle-SymbolicName> is computed using the shared Maven2OsgiConverter component, which uses the following algorithm:
    Get the symbolic name as groupId + "." + artifactId, with the following exceptions:
    • if artifact.getFile is not null and the jar contains a OSGi Manifest with Bundle-SymbolicName property then that value is returned
    • if groupId has only one section (no dots) and artifact.getFile is not null then the first package name with classes is returned. eg. commons-logging:commons-logging -> org.apache.commons.logging
    • if artifactId is equal to last section of groupId then groupId is returned. eg. org.apache.maven:maven -> org.apache.maven
    • if artifactId starts with last section of groupId that portion is removed. eg. org.apache.maven:maven-core -> org.apache.maven.core
      The computed symbolic name is also stored in the $(maven-symbolicname) property in case you want to add attributes or directives to it.
  • <Export-Package> is now assumed to be the set of packages in your local Java sources, excluding the default package '.' and any packages containing 'impl' or 'internal'.
    (before version 2 of the bundleplugin it was based on the symbolic name)
  • Since 2.2.0 you can also use {local-packages} inside <Export-Package> and it will be expanded to the set of local packages.
  • <Private-Package> is now assumed to be the set of packages in your local Java sources (note that any packages in both <Export-Package> and <Private-Package> will be exported).
    (before version 2 of the bundleplugin it was assumed to be empty by default)
  • <Import-Package> is assumed to be "*", which imports everything referred to by the bundle content, but not contained in the bundle.
    Any exported packages are also imported by default, to ensure a consistent class space.
  • <Include-Resource> is generated from the project's Maven resources, typically "src/main/resources/", which will copy the specified project directory hierarchy into the resulting bundle JAR file, mirroring standard Maven behavior.
  • <Bundle-Version> is assumed to be "${pom.version}" but is normalized to the OSGi version format of "MAJOR.MINOR.MICRO.QUALIFIER", for example "2.1-SNAPSHOT" would become "2.1.0.SNAPSHOT".
  • <Bundle-Name> is assumed to be "${pom. with '-' character separator of the qualifier replaced with a '.' character.<Bundle-Name> is assumed to be "${pom.name}".
  • <Bundle-Description> is assumed to be "${pom.description}".
  • <Bundle-License> is assumed to be "${pom.licenses}".
  • <Bundle-Vendor> is assumed to be "${pom.organization.name}".
  • <Bundle-DocURL> is assumed to be "${pom.organization.url}".

...

Code Block
xml
xml
<plugin>
  <groupId>org.apache.felix</groupId>
  <artifactId>maven-bundle-plugin</artifactId>
  <executions>
    <execution>
      <id>bundle-manifest</id>
      <phase>process-classes</phase>
      <goals>
        <goal>manifest</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <supportedProjectTypes>
      <supportedProjectType>jar</supportedProjectType>
      <supportedProjectType>bundle</supportedProjectType>
      <supportedProjectType>war</supportedProjectType>
    </supportedProjectTypes>
    <instructions>
      <!-- ...etc... -->
    </instructions>
  </configuration>
</plugin>

Building the Plugin

The plugin is hosted at the Apache Felix project. The following steps describe how to build and install the plugin into your local Maven2 repository.

You'll also need to configure the other plugin to pick up and use the generated manifest, which is written to ${project.build.outputDirectory}/META-INF/MANIFEST.MF by default (unless you choose a different manifestLocation in the maven-bundle-plugin configuration). Continuing with our WAR example:

Code Block

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <configuration>
    <archive>
      <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
    </archive>
  </configuration>
</plugin>

Building the Plugin

The plugin is hosted at the Apache Felix project. The following steps describe how to build and install the plugin into your local Maven2 repository.

Using the SVN client of your choice, checkout the maven-bundle-plugin project.Using the SVN client of your choice, checkout the maven-bundle-plugin project.

No Format
$ svn co http://svn.apache.org/repos/asf/felix/trunk/bundleplugin

...

The MATCH section accepts alternatives, separated by |, and can be negated by using ! at the beginning of the MATCH. Use * to represent zero or more unknown characters and ? to represent a single unknown zero or one character. You can also use standard Java regexp constructs. There is no need to escape the . character inside MATCH. The first MATCH in a clause will filter against the artifactId.

...

Sometimes you would like to clean your local OBR because it contains bundles that are no longer in your local Maven repository. This case often occurs when artifacts were deleted manually. The maven-bundle-plugin provides a simple goal to check for missing bundles, and remove them from the local OBR., and remove them from the local OBR.

configuration:

  • obrRepository path to local OBR, defaults to <local-maven-repository>/repository.xml

Example:

No Format

mvn bundle:clean

bundle:index

The index goal allows the creation of an OBR repository based on a set of jars in a maven repository.

Configurationconfiguration:

  • obrRepository path to local OBR, defaults to <local-maven-repository>/repository.xml

Example:

...

  • urlTemplate template for generating urls for OBR resources
  • mavenRepository path to the maven repository, defaults to <local-maven-repository>

Possible values for the urlTemplate are:

  • maven this will create a maven based url such as mvn:groupid/artifactid/version
  • pattern with the following placeholders:
    • %v bundle version
    • %s bundle symbolic name
    • %f file name
    • %p file path

Concurrent updates

With a remote OBR, several uploads may occur at the same time. However, the remote OBR is centralized in one file, so concurrent modification must be avoided. To achieve this, the plug-in implements a locking system. Each time the plug-in tries to modify the file it sets a file based lock. If it can't take the lock, it will wait and retry. After 3 attempts the upload process fails. To bypass this lock add -DignoreLock to the command-line (or add <ignoreLock>true<ignoreLock> to the configuration section of your Pom).

...