'bnd-maven-plugin', how can be all third party non-osgi jar resolvable on main bundle deployment

787 views
Skip to first unread message

Umesh Rajani

unread,
Oct 21, 2016, 2:04:23 AM10/21/16
to bndtools-users
Hi,

I found many samples using 'maven-bundle-plugin' which explain nicely to add non-osgi third party maven jars in main bundle so it will be resolvable on deployment.
But there is no any sing sample explains how to do using 'bnd-maven-plugin'? If any one faced hurdles like me pl. suggest me.

'bnd-maven-plugin'

'maven-bundle-plugin'

Thank you,
Umesh

Timothy Ward

unread,
Oct 21, 2016, 2:48:52 AM10/21/16
to bndtool...@googlegroups.com
Hi Umesh,

The following example set uses the bnd-maven-plugin https://github.com/paremus/hello-examples. There are also detailed instructions walking you through the project https://docs.paremus.com/pages/viewpage.action?pageId=8060997


I hope this helps.

Regards,

Tim

--
You received this message because you are subscribed to the Google Groups "bndtools-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bndtools-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Umesh Rajani

unread,
Oct 21, 2016, 6:31:11 AM10/21/16
to bndtools-users
Thank you Tim,

This example is really great. Here we want to deploy it on core felix.
Actually we have one project module which has 20-30 external jar dependency, when I just do 'maven install' I will get one myproject_osgi.jar and when I deploy on felix, it should resolve all the third party jar dependency, but it is not. So what is the way to do it? should I deploy all third party jar first on felix one by one? 

Timothy Ward

unread,
Oct 21, 2016, 6:42:18 AM10/21/16
to bndtool...@googlegroups.com
Hi Umesh,

The examples include a description of how to build an index which you can use to provision your third party dependencies. The bndrun file it describes can be used in bndtools to launch a framework. It can also be used

You may also want to look at the bnd export maven plugin https://github.com/bndtools/bnd/tree/master/maven/bnd-export-maven-plugin

This will export a runnable jar to launch your application.

Regards,

Tim

Umesh Rajani

unread,
Oct 21, 2016, 10:04:27 AM10/21/16
to bndtools-users
Thanks Tim,

I can replicate it in my project to run locally. but to export as bundle and then final deployment how can we do that using this export plugin?
Suppose in given example in which module I can keep 'bnd-export-maven-plugin' plugin?
I apologized to ask more and more as I do not find much on this plugin documented.

In which module or parent where we should put  'bnd-export-maven-plugin' ?
  1. helloworld-index
  2. helloworld-web
  3. helloworld
  4. or any other
This configuration for sample example:
<plugin>
 
<groupId>biz.aQute.bnd</groupId>
 
<artifactId>bnd-export-maven-plugin</artifactId>
 
<version>${bnd.version}</version>
 
<configuration>
 
<bndruns>
 
<bndrun>helloworld-web.bndrun</bndrun>
 
</bndruns>
 
<targetDir>.</targetDir>
 
</configuration>
 
<executions>
 
<execution>
 
<goals>
 
<goal>export</goal>
 
</goals>
 
</execution>
 
</executions>
 
</plugin>

Timothy Ward

unread,
Oct 21, 2016, 10:29:34 AM10/21/16
to bndtool...@googlegroups.com
The bnd-export-maven-plugin uses a bndrun file to create a runnable jar (just like Eclipse does). The jar will contain all of the bundles needed to run your application (as defined by the bndrun).

You can see an example project here:


Regards,

Tim

Umesh Rajani

unread,
Oct 24, 2016, 4:50:11 AM10/24/16
to bndtools-users
Hi Tim,

Thank you very much for your great help.

I have gone thru the examples u have given ref. bnd-export-maven-plugin

This can create runnable jar and I can run standalone app but that is not itself OSGi bundle, I want to create osgi bundle with all dependent third party jars inside it then I want deploy on felix. 

Like in the example we have module 'helloworld-api' if I create OSGi bundle and deploy on felix, then I can use these API in many implementation bundle . As of now when I deploy independent helloworld-api.jar on felix, it gives error of 

"org.osgi.framework.BundleException: Unresolved constraint in bundle helloworld-api [10]: Unable to resolve 10.0: missing requirement [10.0] osgi.extender; (&(osgi.extender=osgi.component)(version>=1.3.0)(!(version>=2.0.0)))"

as it is dependent on 'osgi.annotation' 

 <dependencies>
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>osgi.annotation</artifactId>
        </dependency>
    </dependencies>

So what can be the way if I want to create OSGi bundle along with all the dependent third party jars?

Thank you Tim once again, 

Timothy Ward

unread,
Oct 24, 2016, 6:47:39 AM10/24/16
to bndtool...@googlegroups.com
Hi Umesh

If you wish to deploy your application into a running felix framework then I’m afraid that the bnd-export-maven-plugin won’t be helpful to you. The export maven plugin is a really quick and easy way to start and run an application, but it is designed to produce a standard runnable JAR.


I want to create osgi bundle with all dependent third party jars inside it

I would strongly recommend that you don’t do this. It can sometimes make sense to embed a dependency as a specific workaround, but in general you do not want to build monolithic bundles like this. The whole purpose of OSGi is that you can easily replace pieces of the system.


Like in the example we have module 'helloworld-api' if I create OSGi bundle and deploy on felix, then I can use these API in many implementation bundle . As of now when I deploy independent helloworld-api.jar on felix, it gives error of 

"org.osgi.framework.BundleException: Unresolved constraint in bundle helloworld-api [10]: Unable to resolve 10.0: missing requirement [10.0] osgi.extender; (&(osgi.extender=osgi.component)(version>=1.3.0)(!(version>=2.0.0)))"

as it is dependent on 'osgi.annotation' 

 <dependencies>
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>osgi.annotation</artifactId>
        </dependency>
    </dependencies>

I’m afraid that you’ve misdiagnosed the problem here. The extender constraint has nothing to do with osgi.annotation, and instead indicates that you require a Declarative Services implementation. This means that you have a declarative services component declared in the API bundle, which is probably not what you wanted. The Declarative Services component should be declared in its own bundle, separate from the API.

So what can be the way if I want to create OSGi bundle along with all the dependent third party jars?

If you package all the dependencies into a single bundle then the bundle will almost certainly not work. Declarative Services is not designed to be embedded, and would almost certainly not function, and even if it did start it would most likely not find any of the component metadata to build your components.

A much better approach would be to gather your dependencies into a folder and to use a tool like Felix File Install to install those bundles into your framework.

Regards,

Tim

Umesh Rajani

unread,
Oct 24, 2016, 8:04:31 AM10/24/16
to bndtools-users
Thanks Tim,

Okey I got it almost. now want to clear some my doubts.

I'm migrating big enterprise app in OSGi enabled, so I'm exploring/reading many things since one month but not getting clear cut idea how to design OSGi architecture.
We have around 15 project module and every module depends on average 10-20 third party jars. Now I have to split these modules in many in API and Implementation. 

Doubt: If I have that much number of dependent third party jars for many bundle then should I deploy these all third party jars using Felix File Install?
Doubt: After deployment of these third party jar we can then deploy/install developed OSGi bundle on felix or karaf, am I right?
Big doubt: Provided example is still OSGi app even after running with runnable jar, right? Here I want to check plug-able architecture, is it possible with this example? 

Overall idea is design plug-able architecture like Forgerock tools, Eclipse.

Thank you Tim.

Timothy Ward

unread,
Oct 25, 2016, 10:02:16 AM10/25/16
to bndtool...@googlegroups.com
Hi Umesh,

Doubt: If I have that much number of dependent third party jars for many bundle then should I deploy these all third party jars using Felix File Install?

You can deploy as many bundles as you want using Felix File Install. My guess is that there will be a lot of overlap in the modules' dependencies, and so the total will be a lot lower than 300. It’s also worth checking that the dependencies are a) actually needed, and b) correctly scoped. It’s amazing the number of projects that have unnecessary dependencies, or that make JUnit a compile dependency…

Doubt: After deployment of these third party jar we can then deploy/install developed OSGi bundle on felix or karaf, am I right?

Bundles are bundles - you can deploy them on any OSGi framework you want. The only thing that would stop you doing this is if you explicitly use code from a particular framework implementation (for example an Equinox Storage Hook).

Big doubt: Provided example is still OSGi app even after running with runnable jar, right? Here I want to check plug-able architecture, is it possible with this example? 

Yes, if you want you can deploy a management console in your application. This could be a command line server, or it could be something sophisticated like Apache Felix Web Console. You could even add File Install to your runnable jar so that you have an external deployment folder as well.

Regards,

Tim
Reply all
Reply to author
Forward
0 new messages