Build OSGi bundle include dependencies with maven-assembly-plugin
This is quite simple, add the following to your configuration:
<Embed-Dependency>dependencies</Embed-Dependency>
This is basically it. The complete documentation can be found at Felix-Maven-Bundle-Plugin and more details on how BND works can be found at aqute
Regarding, best practices of including. If it's something that just your application needs and is mostly hidden, embedding those dependencies can be a valid solution. If you are reusing this stuff you should think of creating a "shaded" bundle
Ryo
Updated on June 08, 2022Comments
-
Ryo about 2 years
I need to create an OSGi bundle include dependencies ,I'm using maven-assembly-plugin ,and this is my pom.xml
<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> <artifactId>logstat</artifactId> <packaging>bundle</packaging> <name>Log Stat Demo</name> <version>1.0</version> <groupId>org.test</groupId> <dependencies> <dependency> <groupId>org.jruby</groupId> <artifactId>yecht</artifactId> <version>1.0</version> </dependency> <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-json</artifactId> <version>2.2.1</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <version>2.4.0</version> <extensions>true</extensions> <configuration> <instructions> <Export-Package>activator.*,service.*,impl.*</Export-Package> <Bundle-Activator>activator.Activator</Bundle-Activator> </instructions> </configuration> </plugin> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <mainClass>activator.Activator</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> <executions> <execution> <id>make-my-jar-with-dependencies</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
When i run maven build ,it created 2 jars file ,one with dependencies and one without
But in the one with dependencies ,the MANIFEST.MF not include OSGi configuration like :
Manifest-Version: 1.0 Bnd-LastModified: 1392281245886 Build-Jdk: 1.6.0_45 Built-By: myname Bundle-Activator: activator.Activator Bundle-ManifestVersion: 2 Bundle-Name: test Bundle-SymbolicName: org.wiperdog.logstat Bundle-Version: 1.0.0 Created-By: Apache Maven Bundle Plugin Export-Package: activator;uses:="org.osgi.framework";version="1.0.0",ser vice;version="1.0.0",impl;uses:="org.osgi.framework,service";version="1 .0.0" Import-Package: org.jruby.embed;version="[1.7,2)",org.jruby.embed.osgi;v ersion="[1.7,2)",org.osgi.framework;version="[1.6,2)" Tool: Bnd-2.1.0.20130426-122213
it's just have some basic jar configuration ,not OSGi bundle:
Manifest-Version: 1.0 Archiver-Version: Plexus Archiver Created-By: Apache Maven Build-Jdk: 1.6.0_45 Main-Class: activator.Activator
So ,how do I have to configuration ?