5
votes

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?

2

2 Answers

16
votes

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
    
0
votes

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>