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

2

5

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?

Heartbreak answered 16/2, 2015 at 13:32 Comment(0)
P
18

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
    
Parrett answered 16/6, 2015 at 15:34 Comment(0)
M
0

I think what you would want is to have a dependency in the POM with the compile time scope like the example below: use the correct artifact and version info to get the item you want. you should investigate the dependencies section of the maven ref for poms

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>compile</scope>
</dependency>
Mayle answered 8/3, 2015 at 14:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.