Few days back I was writing a Spring Roo add-on(an OSGI bundle) which required me to add some external 3rd party jars to the OSGI bundle pom.xml file. I am not very well verse with OSGI so it took me some time to figure out how to add 3rd party jars to an OSGI bundle. In this short blog post I am sharing the recipe to add third part jars.
The exception that you get when OSGI bundle is not able to find the dependency is like this.
org.osgi.framework.BundleException: Unresolved constraint com.shekhar.roo.addon [66]: Unable to resolve 66.0: missing requirement [66.0] package; (package=com.shekhar.utils)
To solve this error you need to add Embed-Dependency tag to your maven bundle plugin as shown below. The example shows that I need to add commons-io and utils jar to my OSGI bundle. To get more information about Embed-Dependency tag and maven bundle plugin please refer to the documentation.
<plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <version>2.3.4</version> <extensions>true</extensions> <configuration> <instructions> <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> <Bundle-Copyright>Copyright Shekhar Gulati. All Rights Reserved.</Bundle-Copyright> <Bundle-DocURL>${project.url}</Bundle-DocURL> utils,jsch,commons-io;scope=compile|runtime;inline=false</Embed-Dependency> </instructions> <remoteOBR>true</remoteOBR> </configuration> </plugin>
May I just say that after finding Adding Third Party Jars To An OSGI Bundle « Shekhar
Gulati : OpenShift Evangelist, Software Developer, Writer, and Speaker on PHP-Nuke, what a comfort to
come across a person who finally understands what they’re talking about when it comes to this. You seriously grasp how to bring a problem to light and make it important. A lot more people need to look at this and understand this perspective. It’s surprising you’re not more well-known, because you most certainly possess the gift.
did you miss at the begin of the line?
did you miss Embed-Dependency tag at the begin of the line (inside the piece of code)?
thanks this was helpful.