Fork me on GitHub

Usage

Best practice is to define the version of the OSGi distribution plugin that you want to use in either your pom.xml or a parent pom.xml.

<project>
    [...]
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>fr.liglab.adele.common</groupId>
                    <artifactId>maven-osgi-distribution-plugin</artifactId>
                    <version>1.0.3-SNAPSHOT</version>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
    [...]
</project>

To use the maven-osgi-distribution-plugin Plugin, you need to add the following configuration to your pom.xml

<project>
    [...]
    <packaging>osgi-distribution</packaging>
    [...]
    <build>
        <plugins>
            <plugin>
                <groupId>fr.liglab.adele.common</groupId>
                <artifactId>maven-osgi-distribution-plugin</artifactId>
                <version>1.0.3-SNAPSHOT</version>
                <extensions>true</extensions>
            </plugin>
        </plugins>
    </build>
    [...]
</project>

The maven-osgi-distribution-plugin Plugin is invoked during the:

  • process-resources phase : copy dependencies to the configured directories
  • package phase: build the application package

A full run, executing all the above steps:

mvn clean install

Configuration Options

Plugin configuration options:

  • defaultOutputDirectory to specify the location of the artifacts declared in the dependency section. Except for artifacts defined in the outputs section. Default value load.
  • generateScripts to generate launcher temporal scripts (useful while testing distribution) Default value false.
  • flattenDP to specify if Deployment-Packages dependencies will be flatten in the distribution or not. Default value false.
  • outputs used to configure target location for some artifacts.
  • output the entry to define the desired artifact.
  • IncludesArtifactId the artifactId.
  • directory the target directory location of the current artifact.
  • outputFileName if defined, the artifact filename will be overrided by this value.

Configuration Example

An output configuration example :

<outputs>
    <output>
        <IncludesArtifactId>org.apache.felix.main</IncludesArtifactId>
        <directory>bin</directory>
        <outputFileName>felix.jar</outputFileName>
    </output>
    <output>
        <IncludesArtifactId>org.apache.felix.fileinstall</IncludesArtifactId>
        <directory>bundles</directory>
    </output>
</outputs>

Results in the following :

  • The felix dependency will be redirected to the "bin" directory, and will be renamed to "felix.jar".
  • The fileinstall dependency will be redirected to the "bundles" directory.
  • All other dependencies go to the "load" folder (default behavior).

Projects using this plugin need to use the "osgi-distribution" packaging type, and call the plugin in their plugins section.

<build>
    <plugins>
        <plugin>
            <groupId>fr.liglab.adele.common</groupId>
            <artifactId>maven-osgi-distribution-plugin</artifactId>
            <version>@project.version@</version>
            <extensions>true</extensions>
            <configuration>
                <defaultOutputDirectory>bundle</defaultOutputDirectory>
                <generateScripts>true</generateScripts>
                <outputs>
                    ...
                </outputs>
            </configuration>
        </plugin>
    </plugins>
</build>

To run the plugin, just call the "install" goal on your project.

Flatten Deployment packages

By default the plugin copy all deployment packages defined as project dependencies. If you prefer not to rely on deployment packages, you can ask to flatten all deployment packages using flattenDP configuration option:

<project>
    [...]
    <packaging>osgi-distribution</packaging>
    [...]
    <build>
        <plugins>
            <plugin>
                <groupId>fr.liglab.adele.common</groupId>
                <artifactId>maven-osgi-distribution-plugin</artifactId>
                <version>1.0.3-SNAPSHOT</version>
                <extensions>true</extensions>
                <configuration>
                    <flattenDP>true</flattenDP>
                </configuration>
            </plugin>
        </plugins>
    </build>
    [...]
</project>

Adding files to OSGi distribution package

You can set additional files to be appended to the OSGi distribution zip file. You only need to put them into the src/main/resources folder. Relative path to copied resources is preserved into the zip file.