Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

No Format
...
<plugins>
  <plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>bundle<artifactId>maven-bundle-plugin</artifactId>
    <extensions>true</extensions>
    <configuration>
      <instructions>
        <Export-Package>org.foo.myproject.api</Export-Package>
        <Private-Package>org.foo.myproject.*</Private-Package>
        <Bundle-Activator>org.foo.myproject.impl1.Activator</Bundle-Activator>
      </instructions>
    </configuration>
  </plugin>
<plugins>
...

...

In the case of assignment or simple forms, the PATH parameter can point to a file or directory. The simple form will place the resource in the bundle JAR with only the file name, i.e., without any path component. For example, including src/a/b.c will result in a resource b.c in the root of the bundle JAR. If the PATH points to a directory, the directory name itself is not used in the bundle JAR. If a resource must be placed in a subdirectory of the bundle jar, then use the assignment form. The inline requires a ZIP or JAR file, which will be completely expanded in the bundle JAR.

If a resource clause is specified inside of "{{{ ... }}}" then variable substitution will be performed on the resource, where variables in the resources are denoted with "${ ...}" syntax.

<Import-Package>

The <Import-Package> instruction is a list of packages that are required by the bundle's contained packages. The default for this header is "*", resulting in importing all referred packages. This header therefore rarely has to be specified. However, in certain cases when there is an unwanted import, such an import can be removed by using a negation package pattern.

...

Anchor
how-to
how-to

Detailed "How To"

Get Maven2

The first step in the process of using the plugin is downloading and installing the latest version of the Maven2 runtime. The latest Maven2 release and instuctions for getting started with Maven2 can be found at the Maven website.

Getting the Plugin

The plugin is hosted at the Apache Felix incubator project. The following steps describe how to build and install the plugin into your local Maven2 repository (after having installed Maven2 above):

  1. Using the SVN client of your choice, checkout the Maven 2 OSGi plugin project.
No Format

$ svn co http://svn.apache.org/repos/asf/incubator/felix/trunk/tools/maven2/maven-bundle-plugin
  1. Using Maven2, build and install the maven-bundle-plugin by issuing the following Maven2 command in the project directory that was created as a result of step 1.
No Format

$ mvn install

Using the maven-osgi-plugin

To use the maven-osgi-plugin, you first need to add the plugin and some appropriate plugin configuration to your project's POM. Below is an example of a simple OSGi bundle POM for Maven 2:

No Format

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>my-osgi-bundles</groupId>
  <artifactId>simple</artifactId>
  <packaging>bundle</packaging>    <!-- (1) -->
  <version>1.0</version>
  <name>Example Bundle</name>
  <build>
    <plugins>
      <plugin>    <!-- (2) START -->
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <extensions>true</extensions>
        <configuration>
          <instructions>
            <Export-Package>com.my.company.api</Export-Package>
            <Private-Package>com.my.company.*</Private-Package>
            <BundleActivator>com.my.company.Activator</BundleActivator>
          </instructions>
        </configuration>
      </plugin>    <!-- (2) END -->
    </plugins>
  </build>
  <dependencies>
    <dependency>
      <groupId>org.apache.felix</groupId>
      <artifactId>org.osgi.core</artifactId>
      <scope>provided</scope>
    </dependency>
  </dependencies>
</project>

Three things to note: (1) the <packaging> specifier, (2) the plugin and configuration specification, and (3) the <scope> specifier on the dependency. The org.osgi-3.0.jar is a compile-time dependency, but the scope specifier indicates that our OSGi container will provide the dependency at runtime so there is no need to embed the dependent jar into the bundle archive.