Developers, Developers, Developers! Maksim Sorokin IT Blog

9Aug/11Off

Maven + Apache Felix: Strategy to Handle non-OSGi Dependencies

This is another post in Maven + Apache Felix + CXF + DOSGi series.

Sometimes in the project plain Maven dependencies has to be used. A simple strategy to use those in OSGi project handled by Maven is to have a separate module, containing all non-OSGi dependencies and converting those to OSGi bundles using Apache Felix Maven Bundle Plugin.
So one may have the following structure of the project:

project
    ...
    project.nonOsgiDependencies
        project.nonOsgiDependencies.base64
        project.nonOsgiDependencies.mysqlConnector
        project.nonOsgiDependencies.xercesImpl

This nonOsgiDependencies projects would contain just a pom.xml file, which would have a dependency on required maven dependency and would use maven-bundle-plugin to wrap it. Here is an example of such pom.xml for net.iharder:base64

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <artifactId>project.nonOsgiDependencies</artifactId>
    <groupId>dk.sorokin.maksim</groupId>
    <version>1.0.0-SNAPSHOT</version>
  </parent>

  <artifactId>ecosystem.nonOsgiDependencies.base64</artifactId>

  <name>net.iharder:base64 Maven Dependency</name>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <executions>
          <execution>
            <id>wrap-dependency</id>
            <goals>
              <goal>bundle</goal>
            </goals>
            <configuration>
              <instructions>
                <Embed-Dependency>*</Embed-Dependency>
                <Export-Package>net.iharder</Export-Package>
              </instructions>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <dependency>
      <groupId>net.iharder</groupId>
      <artifactId>base64</artifactId>
      <version>2.3.8</version>
    </dependency>
  </dependencies>
</project>
Comments (0) Trackbacks (0)

Sorry, the comment form is closed at this time.

Trackbacks are disabled.