Creating an OSGi bundle with Maven

This article explains the creation of an OSGi bundle with Maven that integrates JPA and TopLink Essentials as library. This is often needed if an application is distributed on top of an OSGi platform like Eclipse Equinox or Apache Felix.

Maven has a plugin that can be used to create OSGi bundles. The most important part about this plugin is the configuration. The next listing contains the complete configuration followed by explanations to important elements especially in conjunction with TopLink Essentials. The plugin configuration is part of the pom files build section.

Beside TopLink Essentials this also integrates the JGoodies libraries (Forms, Binding and Validation) in the bundle.

<plugin>
  <groupId>org.apache.felix</groupId>
  <artifactId>maven-bundle-plugin</artifactId>
  <version>1.4.1</version>
  <extensions>true</extensions>
  <configuration>
    <instructions>
      <Embed-Dependency>
        *;scope=compile|runtime;inline=false;
            groupId=com.jgoodies|toplink.essentials;
            artifactId=forms|binding|validation|toplink-essentials
      </Embed-Dependency>
      <Import-Package>
        !org.apache.tools.ant.*,
        *
      </Import-Package>
      <_exportcontents>com.jgoodies.*,javax.persistence.*</_exportcontents>
      <Export-Package>
        net.sf.daro.core,
        net.sf.daro.core.binding.*,
        net.sf.daro.core.util.*,
        net.sf.daro.core.swing.*,
        net.sf.daro.core.page,
        net.sf.daro.core.form,
      </Export-Package>
      <Private-Package>
        net.sf.daro.core.internal.*,
      </Private-Package>
      <Bundle-Activator>
        net.sf.daro.core.internal.CorePlugin
      </Bundle-Activator>
      <Bundle-Vendor>Daniel Rohe</Bundle-Vendor>
      <Bundle-SymbolicName>${artifactId}</Bundle-SymbolicName>
    </instructions>
  </configuration>
</plugin>

The first important section is the embed-dependency section. This defines the dependencies that should be embedded into the bundle and loaded into the classpath. In this case all dependencies with the scope compile or runtime that match the groupId com.jgoodies or toplink.essentials and the artifactId forms, bindings, validation or toplink-essentials are imported. This filter exactly matches the three JGoodies libraries and the single TopLink Essentials library.

The next section with the name import-package defines the package imports. In this section I excluded all imports to org.apache.tools.ant because they aren’t needed when integrating TopLink Essentials into an application.

The section _exportcontents exports the listed packages which are part of an embedded dependency.

Schlagwörter: , , ,

Schreibe einen Kommentar

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

WordPress.com-Logo

Du kommentierst mit Deinem WordPress.com-Konto. Abmelden / Ändern )

Twitter-Bild

Du kommentierst mit Deinem Twitter-Konto. Abmelden / Ändern )

Facebook-Foto

Du kommentierst mit Deinem Facebook-Konto. Abmelden / Ändern )

Google+ Foto

Du kommentierst mit Deinem Google+-Konto. Abmelden / Ändern )

Verbinde mit %s

%d Bloggern gefällt das: