Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to embed a library JAR in an OSGi bundle using Tycho

I am using Maven with the Tycho plugin to build my OSGi bundles. In one of my bundles, I use the facebook API through the restfb-1.7.0.jar library.

For now, it is directly placed on the classpath (in Eclipse) and embedded in the effective OSGi bundle jar file with following build.properties configuration:

source.. = src/
output.. = bin/
bin.includes = META-INF/,\
           .,\
           lib/restfb-1.7.0.jar

Now I would like to have this restfb lib downloaded from Maven (e.g. as dependency) and embedded into my OSGi bundle jar. Is it possible with Maven/Tycho? How?

like image 916
Wojtek Avatar asked Feb 16 '15 13:02

Wojtek


1 Answers

You need the following configuration to embed a JAR into an OSGi plugin with Tycho:

  1. In the pom.xml, configure the copy goal of the maven-dependency-plugin

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.10</version>
                <executions>
                    <execution>
                        <id>copy-libraries</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <item>
                                    <groupId>com.restfb</groupId>
                                    <artifactId>restfb</artifactId>
                                    <version>1.7.0</version>
                                </item>
                            </artifactItems>
                            <outputDirectory>lib</outputDirectory>
                            <stripVersion>true</stripVersion>
                            <overWriteReleases>true</overWriteReleases>
                            <overWriteSnapshots>true</overWriteSnapshots>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    
  2. Edit the MANIFEST.MF to have the library added to the OSGi bundle classpath

    Bundle-ClassPath: ., lib/restfb.jar
    
  3. Edit the build.properties to have the library included in the JAR packaged by Tycho

    bin.includes = META-INF/,\
                   .,\
                   lib/restfb.jar
    
like image 78
oberlies Avatar answered Sep 28 '22 06:09

oberlies